1

我有一个使用石英 cron 触发器的弹簧应用程序。我给出了以下频率 0 0/20 * * * ?.....每 20 分钟一次。但我希望第一个立即运行。现在,当我启动应用程序时,它会在 20 分钟后运行。我希望它会尽快运行,然后在 20 分钟后运行。

提前致谢。

4

2 回答 2

1

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

于 2013-01-29T20:06:38.013 回答
0

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.

于 2013-01-29T20:06:40.900 回答