我的控制器类别为:
private Trigger buildJobTrigger(JobDetail job, ZonedDateTime startAt) {
return TriggerBuilder.newTrigger()
.forJob(job)
.withIdentity(job.getKey().getName(), "hourly update-triggers")
.withDescription("Send updated hour trigger")
.startAt(Date.from(startAt.toInstant()))
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 * ? * * "))
.build();
// .withSchedule(SimpleScheduleBuilder.simpleSchedule()
// .withIntervalInHours(1))
// .repeatForever()
// .withMisfireHandlingInstructionNextWithExistingCount())
// .build();
// .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0/1 * * ?"))
}
我的组件类是:
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("Executing Job with key {}"+ jobExecutionContext.getJobDetail().getKey());
System.out.println("--------------------------------------------------------------------");
System.out.println("MyJob start: " + jobExecutionContext.getFireTime());
JobDetail jobDetail = jobExecutionContext.getJobDetail();
System.out.println("Example name is: " + jobDetail.getJobDataMap().getString("example"));
System.out.println("MyJob end: " + jobExecutionContext.getJobRunTime() + ", key: " + jobDetail.getKey());
System.out.println("MyJob next scheduled time: " + jobExecutionContext.getNextFireTime());
System.out.println("--------------------------------------------------------------------");
}
我正在输出:
MyJob start: Wed Nov 27 19:00:00 IST 2019
Example name is: null
MyJob end: -1, key: 1456.93.d6216687-c2c1-4503-87ac-3f2160ccf393
MyJob next scheduled time: Wed Nov 27 20:00:00 IST 2019
--------------------------------------------------------------------
Executing Job with key {}1456.93.de9dcbf8-3894-4d13-b5a0-5527e70865f6
--------------------------------------------------------------------
MyJob start: Wed Nov 27 19:00:03 IST 2019
Example name is: null
MyJob end: -1, key: 1456.93.de9dcbf8-3894-4d13-b5a0-5527e70865f6
MyJob next scheduled time: Wed Nov 27 20:00:00 IST 2019
---------------------------------------------------------------