Quartz 调度:使用 DailyCalendar

发布于 2024-10-21 04:07:15 字数 981 浏览 5 评论 0原文

我正在尝试根据以下计划安排石英作业:

作业每天运行,并且只能在上午 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

維他命╮ 2024-10-28 04:07:15

您似乎没有在触发器上设置重复计数或重复间隔。因此它只会在当前时刻触发一次(因为您没有设置未来的开始时间),这可能恰好是在日历的排除时间内 - 这就是为什么它会被计算为永远不会触发。

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.

甜心 2024-10-28 04:07:15

作业每天都会运行,并且只能
上午 9:30 至下午 6:00 之间执行。

在该时间范围内应该多久执行一次作业?一次?一小时一次?每10秒一次?

您需要定义触发器的重复间隔。看看SimpleTriggersetRepeatInterval(long RepeatInterval)方法。它以毫秒为单位定义触发器重复的时间间隔。

Job runs daily and should only be
executed between 9:30am and 6:00pm.

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 of SimpleTrigger. It defines in milliseconds the interval with which the trigger will repeat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文