每 N 小时/天/周/月执行的 cron 触发器的 Quartz cron 表达式 [英] Quartz cron expression for cron triggers executed every Nth Hour/Day/Week/Month
问题描述
我正在开发一个应用程序,让用户能够安排一些活动.用户提供的输入是
I am developing an application that gives the user the ability to schedule some activity. Inputs that are provided by user are
- N 的值
- 小时/天/周/月之间的选项
- 开始日期
- 开始时间
我无法为每个重复间隔类型(即小时/天/周/月)获得正确的 cron 表达式,以便从开始日期开始计算触发时间.
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.
推荐答案
Quartz 文档建议使用 SimpleTrigger http://www.quartz-scheduler.org/docs/cookbook/BiDailyTrigger.html,每隔一天举一个例子:
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.
这篇关于每 N 小时/天/周/月执行的 cron 触发器的 Quartz cron 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!