如何在 Quartz 调度程序中每 25 秒运行一次?
我正在使用 Java 的 Quartz Scheduling API。你能帮我使用 cron 表达式每 25 秒运行一次吗?这只是一个延迟。它不必总是从第 0 秒开始。例如,序列如下:0:00、0:25、0:50、1:15、1:40、2:05 等,直到第 5 分钟序列再次从第 0 秒开始。 谢谢。
I am using the Quartz Scheduling API for Java. Could you help me to run every 25 seconds using cron-expression. It's just a delay. It does not have to start always at second 0. For example, the sequence is like this: 0:00, 0:25, 0:50, 1:15, 1:40, 2:05, etc until minute 5 when the sequence begins again at second 0.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我不认为 cron 表达式允许你这样做,但你可以使用
300(5 分钟)是 25 的倍数,它会自动重复。
I don't think cron expression will allow you to do that, but you can use
as 300 (5 minutes) is a multiple of 25 it will repeat automatically.
如果您希望定期触发作业,则可以使用指定了
repeatInterval
的 QuartzSimpleTrigger
。If you want a job to trigger at a regular interval then you can use a Quartz
SimpleTrigger
with arepeatInterval
specified.使用 Quartz 2.1.5 这将有助于:
With Quartz 2.1.5 this will help:
使用 cron 触发器来做到这一点的唯一方法非常复杂,以至于毫无用处;使用其他答案中的 SimpleTrigger 会更好。然而,如果必须是 cron,则需要设置五个不同的 cron 触发器:
第一个触发器在 0:00:25、0:00:50 触发;第一个触发器在 0:00:25、0:00:50 触发;然后第二个触发器在 0:01:15 和 0:01:40 触发;第三个时间为 0:02:05、0:02:30、0:02:55;第四个在 0:03:20、0:03:45;最后是第五次,时间为 0:04:10 和 0:04:35。然后第一个触发器在 0:05:00 再次接管,依此类推。
这只有效,因为 25 秒均匀地分为 5 分钟(又均匀地分为 1 小时)。如果您想要每 23 秒一次?忘了它吧!
The only way to do this with a cron trigger is so complicated as to be useless; you're much better off with the SimpleTrigger from other answers. Nevertheless, if it has to be cron, you need to set up five different cron triggers:
The first trigger fires at 0:00:25, 0:00:50; then the second trigger fires at 0:01:15 and 0:01:40; the third at 0:02:05, 0:02:30, 0:02:55; the fourth at 0:03:20, 0:03:45; and finally the fifth at 0:04:10 and 0:04:35. The first trigger then takes over again at 0:05:00, etc.
This only works because 25 seconds divides evenly into 5 minutes (which in turn goes evenly into an hour). If you wanted it every 23 seconds? Forget about it!
- [wiki] http://en.wikipedia.org/wiki/Cron
- [quartz 教程] http://www.quartz-scheduler.org/docs/教程/TutorialLesson06.html
- [wiki] http://en.wikipedia.org/wiki/Cron
- [quartz tutorial] http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson06.html
对于石英来说,你不可能有这样的时间表。
您可以做的一件事是安排包装作业每 5 秒运行一次,并且每五次执行才执行任何工作。
You can't have a schedule like that for quartz.
One thing you could do is schedule a wrapper job to run every 5 seconds, and only do any work every fifth execution.
您可以安排作业不断运行,但使用 Camel 的 Throttler 来限制频率。
You could schedule the job to run constantly but throttle the frequency using Camel's Throttler.