quartz spring cron trigger fire immediately

夙愿已清 提交于 2019-12-08 22:03:30

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)

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.

If you really want to use Quartz, check out SimpleTrigger.

It sounds like you want to use an interval trigger (SimpleTrigger in Quartz can do the job). The CronTrigger wants you to specify the minutes at which to run.

So your trigger schedule says: start at 0 minutes, and run every 20 minutes after that until the hour is over. Then start at 0 again.

But with the SimpleTrigger, you say - start now and run every 20 minutes.

Here is a tutorial on SimpleTrigger: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-05

Here is a tutorial on CronTrigger: http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!