两个日期之间的 Quartz CronTrigger 表达式
有没有办法编写一个在两个日期之间每天运行的 Quartz CronTrigger 表达式,例如从 2011 年 9 月 5 日上午 11 点开始,到 2012 年 6 月 10 日上午 11 点结束?
Is there a way to write a Quartz CronTrigger expression that runs every day between two dates, for example starts at 11am 5th of Sep 2011 and ends at 11am 10th of June 2012?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用表示每天上午 11:00 的表达式,例如“0 0 11 * * ?”。
然后将触发器的 startTime 设置为 2011 年 9 月 5 日上午 10:59,并将触发器的结束时间设置为 2012 年 6 月 10 日上午 11:01。
Use an expression that means every day at 11:00am e.g. "0 0 11 * * ?".
Then set the startTime of the trigger to 5th of Sep 2011 10:59 am, and set the endTime of the trigger to 10th of June 2012 11:01 am.
我发现的另一个解决方案是为计划的路线指定一个路线策略(SimpleScheduledRoutePolicy),并为此策略对象设置 RouteStartDate 和 setRouteStopDate。
Another solution I found is to specify a route policy (SimpleScheduledRoutePolicy) for the scheduled route and set the RouteStartDate and setRouteStopDate for this policy object.
单个 cron 表达式不便于为同一期间类型运行不同的计划,无论涉及哪个期间,您的不同计划都是年份期间。
然而,除了年份差异外,所有其他时期都有相同的时间表。所以...使用这些 cron 表达式:
cron1 = "0 0 23 5/1 SEP-DEC ? 2012"
cron2 = "0 0 23 1/1 JAN-JUN ? 2013"
您可以在 2012 年 12 月 31 日晚上 11:00.00 之后但在 2013 年 1 月 1 日晚上 10:59.99 之前将调度程序从使用 cron1 切换到 cron2,尽管我不会将其剪得如此接近,如此处所示。如果您的调度程序正在从数据库或某处的配置中读取其 cron 表达式,那么只需在每天晚上 11:30 读取新的计划即可。如果您将 cron 表达式存储在数据库中,您可以安排调度程序使用下面的 chron3 交换特定任务的 cron 表达式:
cron3 =“0 0 0 1 一月?2013”
愚蠢的我:o) 今天的日期是 2013 年 3 月 13 日,所以我确信这个答案对您来说有点晚了!
A single cron expression doesn't facilitate running different schedules for the same period type, no matter which period is concerned, your differing schedule being the year period.
However other than your year difference all other periods have the same schedule. So... using these cron expressions:
cron1 = "0 0 23 5/1 SEP-DEC ? 2012"
cron2 = "0 0 23 1/1 JAN-JUN ? 2013"
you can switch the scheduler from using cron1 to cron2 sometime after 11:00.00 PM on 12/31/2012 but before 10:59.99 PM on 1/1/2013, though I wouldn't cut it so close as shown here. If you scheduler is reading its cron expression from the database or a configuration somewhere then just have it read in a new schedule every day at 11:30 PM. If you are storing your cron expressions in a database you could schedule to have a scheduler swap out the cron expression for your particular task using this chron3 below:
cron3 = "0 0 0 1 JAN ? 2013"
Silly me :o) today's date is Mar 13, 2013 so I'm sure this answer is a bit late for you!