当我将 startDate 和 endDate 设置为 Trigger 时,ChronSchedule 只对作业调用一次执行方法。
JobDetail job = JobBuilder.newJob(service)
.withIdentity(batchService.getName(), CommonConstants.BATCH_JOB_GROUP).build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity(batchService.getName(), CommonConstants.BATCH_JOB_GROUP)
.startAt(startDate)
.endAt(endDate)
.withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.build();
System.out.println("##########" + trigger.getEndTime());
System.out.println("##########" + trigger.getStartTime());
如您所见,我在触发器上放了一些打印以获取开始日期和结束日期。这似乎是正确的:
##########Fri Oct 20 16:00:00 CEST 2017
##########Fri Oct 20 15:00:00 CEST 2017
在执行方法中,我打印了一个:
public void execute(JobExecutionContext context) throws JobExecutionException
{
System.out.println("Executing job. The next: " + context.getNextFireTime());
}
但结果令人不安:
Executing job. The next: null
我做错了什么?