【发布时间】:2013-10-03 18:51:33
【问题描述】:
我正在使用 Quartz-Scheduler 执行重复性任务,但我遇到了麻烦。在我的服务器端,我的用户想要指定一些日期范围,例如 From 2013-09-27 with in 09:00 AM - 12:00 PM to 2013-09-30
解释:
从2013-09-27 到2013-09-30 运行作业,但只能在09:00 AM - 12:00 PM 之间运行
我在为其编写 Cron 表达式时遇到了麻烦,此外,我的用户不是技术人员,因此我的用户希望我从两个时间戳值自动创建 Cron 表达式。
请帮帮我。如果有其他方法,请告诉我。
我在 Google 上看过很多资源,但还是什么都找不到。
链接:
http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-05
Does cron expression in unix/linux allow specifying exact start and end dates
更新
我写了一个,但它不起作用
|------------------------------------------------------------------|
| Seconds | Minutes | Hours | DayOfMonth | Month | DayOfWeek | Year|
| | | | | | | |
| 0 | 0 | 9-12 | 27-30 | 9 | ? | 2013|
|------------------------------------------------------------------|
尝试将2013-09-27 映射到2013-09-30,但仅限于09:00 AM - 12:00 PM 之间
更新 我也试过用
运行它Trigger trigger = TriggerBuilder.newTrigger().withIdentity(NAME_TRIGGER_TASK_UPDATER, GROUP_TASK_TRIGGER)
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 9-12 19-22 10 ? *")).build();
但它没有给出任何错误,也没有进入我工作的执行方法
cronSchedule("0 0 9-12 ? * ?") throws invalid schedule exception.
下面的代码在不考虑开始和结束日期的情况下运行它。
String startDateStr = "2013-09-27 00:00:00.0";
String endDateStr = "2013-09-31 00:00:00.0";
Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(startDateStr);
Date endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(endDateStr);
CronTrigger cronTrigger = newTrigger()
.withIdentity("trigger1", "testJob")
.startAt(startDate)
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 9-12 * * ?"))
.endAt(endDate)
.build();
【问题讨论】:
-
你的 cron 表达式在我看来是正确的。您的应用程序中的其他石英触发器和作业是否按预期执行?
-
不只是运行这个:-( Quartz Scheduler Java 有什么不同吗?
标签: java cron quartz-scheduler