我正在使用Firebase JobDispatcher安排要在特定时间执行的作业。我已经测试了2分钟执行间隔的作业计划。下面是JobDispatcher代码。
job = dispatcher.newJobBuilder()
.setLifetime(Lifetime.FOREVER)
.setService(MerchantJobService.class)
.setTag(JOB_TAG_ID)
.setReplaceCurrent(false)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(executionStartTime, executionEndTime))
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build();
我已经打印了日志,发现该作业最初按时执行,但是此后执行时间变得不稳定并在每次执行后大部分时间增加。下面是日志执行时间日志。
作业执行时间-> 120,150(以秒为单位)
1- 12:25:48 --- 12:28:18 === 2 minutes 30 seconds
2- 12:28:18 --- 12:29:18 === 1 minutes 00 seconds
3- 12:29:18 --- 12:32:57 === 4 minutes 39 seconds
4- 12:32:57 --- 12:39:46 === 6 minutes and 49 seconds
5- 12:39:46 --- 12:47:44 === 7 minutes and 58 seconds
作业执行时间-> 120,120(以秒为单位)
1- 12:51:50 --- 12:54:02 === 2 minutes and 12 seconds
2- 12:54:02 --- 13:15:15 === 21 minutes and 13 seconds
3- 13:15:15 --- 13:24:25 === 9 minutes and 10 seconds
4- 13:24:25 --- 13:33:35 === 9 minutes and 10 seconds