石英弹簧cron立即触发火 [英] quartz spring cron trigger fire immediately
问题描述
我有一个使用石英 cron 触发器的弹簧应用程序.我已经给出了以下频率 0 0/20 * * * ?.....每 20 分钟一次.但我希望第一个立即运行.现在,当我启动应用程序时,它会在 20 分钟后运行.我希望它能尽快运行,然后在 20 分钟后运行.
I have a spring application that uses quartz cron trigger. I have given the following for frequency 0 0/20 * * * ?.....once every 20 min. But i want the first one to run immediately. Right now, when I start the application, it runs after 20 min. I was hoping it would run asap and then after 20 min.
提前致谢.
推荐答案
你不需要 CRON 表达式(和 Quartz!)每 20 分钟运行一次给定的代码.只需使用固定速率(Spring 内置):
You don't need CRON expression (and Quartz at all!) to run given code every 20 minutes. Just use fixed rate (Spring built-in):
@Scheduled(fixedRate=20 * 60 * 1000)
就是这样!默认情况下,第一次调用立即发生,20 分钟后第二次调用.从 Spring 3.2 开始,您甚至可以说 initialDelay=10000
在 10 秒后第一次运行.
That's it! By default first invocation happens immediately, second after 20 minutes. Since Spring 3.2 you can even say initialDelay=10000
to run for the first time after exactly 10 seconds.
如果您真的想使用 Quartz,请查看 SimpleTrigger
.
If you really want to use Quartz, check out SimpleTrigger
.
这篇关于石英弹簧cron立即触发火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!