I started using the TimerService yesterday and an interesting thought crossed my mind. I am wondering whether this idea is vendor specific, or defined in the spec, or neither...
I'll also prefix this by saying that I understand that the TimerService is not designed for accuracy (i.e. in real time systems, etc).
Let's say I defined a Timer as (0, 60*60*1000) - so, zero delay, but runs every hour. And I start it precisely on the hour.
Now, the Application Server is busy (or whatever), so is 10 seconds late getting around to starting my task.
So, does the next task occur 1hr after this one? Which of the below is right?
Scenario1 1st task is 10seconds late - 0h,0m,10secs
2nd task runs 1h after the first, but is also 10seconds late - 1h,0m,20secs
3rd task runs 1h after the second, but is also 10seconds late - 2h,0m,30secs
.... and the tasks drift from the originally intended hourly.
In this case, I'd probably just schedule the Timer to go off once, then at the end of the method, define a new Timer with the delay according to the number of milliseconds to the next hour, therefore silently adjusting for the above.
Scenario2 1st task is 10seconds late - 0h,0m,10secs
2nd task is scheduled from the start point, and is 10seconds late - 1h,0m,10secs
3nd task is scheduled from the start point, and is 10seconds late - 2h,0m,10secs
.... no drift. No silent adjustment code needed.
Scenario1 reminds me of using pennies to adjust the mechanism of Big Ben
Are you saying that the Timer Service is defined in the spec? If so, I kinda gathered that bit!
I did not get you question, and suggest you to download ejb-3_0-fr-spec-ejbcore.pdf from Sun Site, ch 18 is for Timer service.
My knowledge is limited with timer service, regarding the case you have mentioned, I have not done much experiment with timer service.
Timer service is alternative to kron job in Unix & task scheduler in Windows, which promise to run the task at specific time/interval.
It is not for real time accuracy, like Quartz. But it is provided by J2EE container & supports Transaction management & Security (in other case, which you need to manage for integrated timer service in J2EE environment).
I would suggest to look into technical stuff and then share the doubt.
There’s no place like 127.0.0.1. But I'll always remember this tiny ad: