开发者

Java Quartz Cron Trigger

I am using a Quartz Cron trigger in my java program. The Cron expression I used is 0 0 * * * ?

Now I wanted a scheduler to execute once an hour. To test the same started my jboss server and after that I reset my windows time to something like 5:59:45 and at 6:00:00 the scheduler did not fire.

Now the next time I first adjusted the time to say 5:55:00 and then I started the server and lo the scheduler fired at 6:00:00.

Does the server or scheduler maintain time internally, of course initialized with sy开发者_开发技巧stem timing initially ??


According to Quartz CronTrigger source code, the trigger retains the date of the next time it should fire.

I suppose that if you start the server at 6:15:00, Quartz retains 7:00:00 as the next firing time. Changing the server time to 5:55:45 doesn't update the next firing time, and 7:00:00 is retained as next firing time. So the event won't fire at 6:00:00, but instead at 7:00:00.

So, time isn't retained directly, but firing time is retained, and it appears it isn't updated if you change your system clock.


If you use JDBC job store, quartz checks database in one-minute intervals looking for jobs to run for now, using the current system time.

When you move forward the system time, quartz will fire appropriate jobs on next check (that means, within minute).


I also faced the same problem and solution to this problem is:

expression means 0 0 * * * ? i.e. sec, min, hour, day of month, month,day of week. so fire at every start of the hour on every day and every month and every week and whatever be the year that be.

this expression simply states that you want to fire your job and every hour on the start of the hour so it logs the time before your server starts thus if before server start the time passed to any hour time then it will fire on next hour time eg-

1 . you started server at 5:55 but server took 7 min to start thus time is passed 2 min more than 6:00 so next fire time will be 7:00

2 . but if, your server starts successfully at 5:59:59 then it will definately fire at 6:00 for sure because scheduler should run on the start of every hour and server is ready before the 6:00 clock.

note: time changing on windows after the server started will not make the scheduler run as the time is logged by the time server runs.


Upvote for Vivien Barousse's answer, quartz will store every trigger's next fire time. If you are using JDBC JobStore, you can find a table looks like *_QRTZ_TRIGGERS in your database , and COLUMN NEXT_FIRE_TIME stores next fire time in timestamp format .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜