Quartz recovering from multiple days misfire

为君一笑 提交于 2019-12-04 11:04:31
Tomasz Nurkiewicz

Your use case is pretty standard and supported by Quartz. You just need "ignore misfires" policy:

Trigger trigger = newTrigger() 
  .withIdentity("dailyTrigger", "scheduledReportEmail") 
  .withSchedule(dailyAtHourAndMinute(0, 5)
  .withMisfireHandlingInstructionIgnoreMisfires()) 
  .build(); 

This basically means: I don't care that the trigger(s) misfired, just run it as soon as possible (that is most likely at application startup).

To figure out when given trigger was suppose to run (what was the scheduled time as opposed to current time), run this in your job:

void execute(JobExecutionContext context) {
  final Date scheduled = context.getScheduledFireTime()
  //...
}

See also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!