[英]How to run every 25 seconds in Quartz scheduler?
I am using the Quartz Scheduling API for Java. 我正在使用Quartz Scheduling API for Java。 Could you help me to run every 25 seconds using cron-expression.
你能帮我用cron-expression每25秒运行一次吗? 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.
它不必始终在第二个0开始。例如,序列是这样的:0:00,0:25,0:50,1:15,1:40,2:05等等到第5分钟时序列在第二个0开始。谢谢。
I don't think cron expression will allow you to do that, but you can use 我不认为cron表达式会允许你这样做,但你可以使用
SimpleScheduleBuilder.repeatSecondlyForever( 25 )
as 300 (5 minutes) is a multiple of 25 it will repeat automatically. 因为300(5分钟)是25的倍数,它将自动重复。
如果您希望定期触发作业,则可以使用Quartz SimpleTrigger
并指定repeatInterval
。
With Quartz 2.1.5 this will help: 使用Quartz 2.1.5,这将有助于:
CronTrigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.withSchedule(cronSchedule("0/20 * * * * ?"))
.build();
The only way to do this with a cron trigger is so complicated as to be useless; 使用cron触发器执行此操作的唯一方法是如此复杂以至于无用; you're much better off with the SimpleTrigger from other answers.
从其他答案中使用SimpleTrigger你会好得多。 Nevertheless, if it has to be cron, you need to set up five different cron triggers:
然而,如果必须是cron,则需要设置五个不同的cron触发器:
0/25 0/5 * * * *
15/25 1/5 * * * *
5/25 2/5 * * * *
20/25 3/5 * * * *
10/25 4/5 * * * *
The first trigger fires at 0:00:25, 0:00:50; 第一个触发器在0:00:25,0:00:50触发; then the second trigger fires at 0:01:15 and 0:01:40;
然后第二个触发器在0:01:15和0:01:40触发; the third at 0:02:05, 0:02:30, 0:02:55;
第三次是0:02:05,0:02:30,0:02:55; the fourth at 0:03:20, 0:03:45;
第四次是0:03:20,0:03:45; and finally the fifth at 0:04:10 and 0:04:35.
最后是0:04:10和0:04:35的第五个。 The first trigger then takes over again at 0:05:00, etc.
然后第一个触发器在0:05:00再次接管,等等。
This only works because 25 seconds divides evenly into 5 minutes (which in turn goes evenly into an hour). 这只能起作用,因为25秒均匀分为5分钟(而后者均匀分为一小时)。 If you wanted it every 23 seconds?
如果你想每23秒一次? Forget about it!
忘掉它!
*/25 * * * * *
- [wiki] http://en.wikipedia.org/wiki/Cron - [wiki] http://en.wikipedia.org/wiki/Cron
- [quartz tutorial] http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson06.html - [石英教程] http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson06.html
You could schedule the job to run constantly but throttle the frequency using Camel's Throttler. 您可以安排作业持续运行,但使用Camel的Throttler限制频率。
<route>
<from uri="jms:queue:TestQueue"/>
<!-- throttle 1 messages per 25 sec -->
<throttle timePeriodMillis="25000">
<constant>1</constant>
<to uri="bean:TestBean?method=testMethod"/>
</throttle>
</route>
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. 您可以做的一件事是安排一个包装器作业每5秒运行一次,并且每隔五次执行只执行任何工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.