[concurrency-interest] Scheduling tasks using TimerTask

Doug Lea dl at cs.oswego.edu
Sat Nov 6 12:43:23 EDT 2010


On 11/06/10 09:19, George wrote:
>
> I would be very grateful to know if there is any solution in Java to
> maintain second precision on systems with ntp time synchronization enabled
> (linux). In other words, If I schedule a task to be executed after 24hours ,
> it should be executed on the second without any deviation of seconds from
> the set time.


If you are on a system with an unreliable system clock that undergoes
frequent ntp adjustment, you can, instead of requesting a
delay until a given time 24hrs from now, just ask for delay
of a few minutes. Then check deadline yourself --
if you've hit it, trigger action, else recalculate the
next few minutes interval based on current system time and delay again.
This is a little messy, but not hard.

-Doug


More information about the Concurrency-interest mailing list