[concurrency-interest] ScheduledThreadPoolExecutor schdeuling problem ?
dl at cs.oswego.edu
Mon Dec 31 14:28:07 EST 2007
Hanson Char wrote:
> Interestingly when I changed the test to replace all uses of
> milli-time with nano-time, the earlier-than-expected problem seems to
> go away. (Nano-test code below.)
> The lesson/solution seems apparent. Replace all use of
> System.currentTimeMillis() with System.nanoTime().
Yes, It is easily possible for nanoTime-based vs currentTimeMillis-based
duration estimates to differ once in a while;
for example, because the underlying currentTimeMillis
system clock is typically updated less frequently.
On average they balance out, but
if you need consistency across all readings, you should rely on nanoTime.
More information about the Concurrency-interest