[concurrency-interest] Scheduling tasks using TimerTask

George mydevgroup at gmail.com
Sat Nov 6 09:19:31 EDT 2010


Hi,

I am using java.util.Timer to schedule TimerTask at an interval of 24hours,
so for example, if I set a  timer task using Timer.schedule(TimerTask task,
Date tomorrow at 8am), then the actual execution takes place only after 6 to 7
seconds past the set time.

This observation is made on a linux box running jvm 1.6, with ntpd running.
Basically, longer the duration of scheduling more deviation is found. It is
found that the deviation increases linearly. (deviation is measured by using
System.currentTimeMillis- scheduledExecutionTime )
 
But on a standalone system with no ntp synchronization using similar JVM
version (1.6),  the scheduling works on second precision. It just deviates
by 20 to 30 milliseconds and deviation is constant.

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. Will it help if I make the wait time in millisecond to be a
multiple of 10/15ms, based on the systems timer interrupts.

Any suggestions would be highly appreciated. Please let me know if I need to
provide more details on the observation, such as the ntp drift .


Thanks,
George



Hello,
I am using java.util.Timer to schedule TimerTask at an interval of 24hours,
so for example, if I set a  timer task using Timer.schedule(TimerTask task,
Date tomorrow at 8am), then the actual execution takes place only after 6 to 7
seconds past the set time.

This observation is made on a linux box running jvm 1.6, with ntpd running.
Basically, longer the duration of scheduling more deviation is found. It is
found that the deviation increases linearly. (deviation is measured by using
scheduledExecutionTime() - System.currentTimeMillis())
 
But on a standalone system with no ntp synchronization using similar JVM
version (1.6),  the scheduling works on second precision. It just deviates
by 20 to 30 milliseconds and deviation is constant.

I would be very grateful to know if is there 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.
Any suggestions would be highly appreciated. Please let me know if I need to
provide more details on the observation, such as the ntp drift .


Thanks,
George







More information about the Concurrency-interest mailing list