Quartz 调度:使用 DailyCalendar
我正在尝试根据以下计划安排石英作业:
作业每天运行,并且只能在上午 9:30 到下午 6:00 之间执行。我正在尝试通过 DailyCalendar 来实现这一目标。这是我的 DailyCalendar 的样子:
DailyCalendar dCal = new DailyCalendar(startTimeString, endTimeString);
dCal.setTimeZone(TimeZone.getDefault());
dCal.setInvertTimeRange(true);
其中开始和结束时间字符串的格式为 HH:MM
接下来,我尝试安排此作业:
Scheduler myscheduler = StdSchedulerFactory.getDefaultScheduler();
SimpleTrigger trigger = new SimpleTrigger();
myscheduler.addCalendar("todcal", cal, true, true);
trigger.setName("TRIGGER " + alertName);
trigger.setJobName(alertName);
trigger.setJobGroup(alertName);
trigger.setCalendarName("todcal");
logger.info("Adding TOD job");
myscheduler.scheduleJob(trigger); // line causing exception
myscheduler.start();
一旦调用 ScheduleJob,我就会看到以下异常:
Based on configured schedule, the given trigger will never fire.
配置对我来说似乎很好,但我不能找到使用 DailyCalendar 的任何示例代码,所以我在这里可能是错的。请帮忙
I am trying to schedule a quartz job according to the following plan:
Job runs daily and should only be executed between 9:30am and 6:00pm. I am trying to achieve this via DailyCalendar. Here what my DailyCalendar looks like:
DailyCalendar dCal = new DailyCalendar(startTimeString, endTimeString);
dCal.setTimeZone(TimeZone.getDefault());
dCal.setInvertTimeRange(true);
where start and end time strings are of the format HH:MM
Next, I try to schedule this job:
Scheduler myscheduler = StdSchedulerFactory.getDefaultScheduler();
SimpleTrigger trigger = new SimpleTrigger();
myscheduler.addCalendar("todcal", cal, true, true);
trigger.setName("TRIGGER " + alertName);
trigger.setJobName(alertName);
trigger.setJobGroup(alertName);
trigger.setCalendarName("todcal");
logger.info("Adding TOD job");
myscheduler.scheduleJob(trigger); // line causing exception
myscheduler.start();
As soon as scheduleJob is called I see the following Exception:
Based on configured schedule, the given trigger will never fire.
The configuration seems fine to me but I cant find any sample code for using DailyCalendar so I could be wrong here. Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎没有在触发器上设置重复计数或重复间隔。因此它只会在当前时刻触发一次(因为您没有设置未来的开始时间),这可能恰好是在日历的排除时间内 - 这就是为什么它会被计算为永远不会触发。
You don't seem to be setting a repeat count or repeat interval on your trigger. So it will only fire once at the current moment (because you did not set a future start time), which probably happens to be during the calendar's exclusion time - which is why it would be calculated that it will never fire.
在该时间范围内应该多久执行一次作业?一次?一小时一次?每10秒一次?
您需要定义触发器的重复间隔。看看
SimpleTrigger
的setRepeatInterval(long RepeatInterval)
方法。它以毫秒为单位定义触发器重复的时间间隔。How often should the job be executed within that timeframe? Once? Once an hour? Every 10 seconds?
You need to define the repeat interval for your trigger. Look at
setRepeatInterval(long repeatInterval)
method ofSimpleTrigger
. It defines in milliseconds the interval with which the trigger will repeat.