@Slf4j
public class SampleJob implements Job {
@SneakyThrows
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
Thread.sleep(5000);
System.out.println("firetime_______"+jobExecutionContext.getRefireCount()+"________"+jobExecutionContext.getFireTime());
Thread.sleep(5000);
System.out.println("shedulefiretime____"+jobExecutionContext.getRefireCount()+"________"+jobExecutionContext.getScheduledFireTime());
Thread.sleep(5000);
log.info(String.format(" 普通定时任务 SampleJob ! 时间:" + DateUtils.getTimestamp()));
}
}
代码段中固定沉睡片刻,模拟正常业务的执行时间;该作业2秒执行一次。
执行结果:
得出结论:
getFireTime()方法获取的是作业实际的执行的时间。
getScheduledFireTime()方法获取到的是作业预期计划的执行时间。