[concurrency-interest] Scheduling tasks using TimerTask

Tim Peierls tim at peierls.net
Sat Nov 6 12:06:48 EDT 2010


You could try ScheduledExecutorService.scheduleAtFixedRate<http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleAtFixedRate(java.lang.Runnable,
long, long, java.util.concurrent.TimeUnit)>, but it sounds like what you
really want is some kind of cron facility, such as the one provided by
Google App Engine:

http://code.google.com/appengine/docs/java/config/cron.html

<http://code.google.com/appengine/docs/java/config/cron.html>--tim

On Sat, Nov 6, 2010 at 9:19 AM, George <mydevgroup at gmail.com> wrote:

> 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
>
>
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20101106/35b12166/attachment.html>


More information about the Concurrency-interest mailing list