Quartz cron expression for cron triggers executed every Nth Hour/Day/Week/Month

牧云@^-^@ 提交于 2019-12-11 08:54:42

问题


I am developing an application that gives the user the ability to schedule some activity. Inputs that are provided by user are

  1. Value of N
  2. Option amongst Hour/Day/Week/Month
  3. Start Date
  4. Start Time

I am unable to get the cron expressions right for each of the repeat interval type i.e. Hour/Day/Week/Month so that the trigger time is calculated from the start date.


回答1:


Quartz documentation suggests using a SimpleTrigger http://www.quartz-scheduler.org/docs/cookbook/BiDailyTrigger.html, an example for every other day:

Trigger trigger = new SimpleTrigger("trigger1", "group1");
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
// 24 hours * 60(minutes per hour) * 60(seconds per minute) * 1000(milliseconds per second)
trigger.setRepeatInterval(2L * 24L * 60L * 60L * 1000L);

Note that you will need to set the trigger start time and the misfire rule.




回答2:


I think is a good start of how to configure triggers:

http://www.opensymphony.com/quartz/wikidocs/CronTriggers%20Tutorial.html



来源:https://stackoverflow.com/questions/1629078/quartz-cron-expression-for-cron-triggers-executed-every-nth-hour-day-week-month

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