0
當我將startDate和endDate設置爲觸發器時,ChronSchedule只對該作業調用execute方法一次。Java - Quartz CronSchedule不適用於開始日期和結束日期
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
在execute方法,我把打印:
public void execute(JobExecutionContext context) throws JobExecutionException
{
System.out.println("Executing job. The next: " + context.getNextFireTime());
}
但結果是unconfortable:
Executing job. The next: null
什麼有我錯了?