[concurrency-interest] ScheduledThreadPoolExecutor schdeuling problem ?

Doug Lea dl at cs.oswego.edu
Mon Dec 31 08:59:39 EST 2007

Hanson Char wrote:
> (I refer to JDK 6+). It seems a scheduled event via
>   ScheduledThreadPoolExecutor.schedule(Runnable command, long delay,
> TimeUnit unit)
> may occur before the target time.  For example, if an event is
> scheduled to occur 1000ms from now.  The event could actually get
> triggered after 990ms ie 10 ms less than the specified delay.
> Is this a known issue ?  Shouldn't the event be delayed for at least
> the specified delay time ?

I hope David Holmes also answers this, since he knows most about
platform-level timing issues. But I don't know of any problems
that affect ScheduledThreadPoolExecutor in this way. Internally,
methods recheck times to ensure that they do not fire too early.
(See DelayQueue.take and related methods). On some platforms
(including Windows), there may be some *apparent* differences
in times if you are monitoring times with System.currentTimeMillis()
versus System.nanoTime() -- these use different clocks that may become
out of sync. ScheduledThreadPoolExecutor uses nanoTime, which should in
general be more accurate.


More information about the Concurrency-interest mailing list