Looking at the Timer source for Java 1.7, it seems like it uses System.currentTimeMillis() to determine the next execution of the task.
However, looking at the source of ScheduledThreadPoolExecutor , it uses System.nanoTime() .
This means that you will not see this behavior if you use it instead of Timer . To create one, use, for example, Executors.newScheduledThreadPool() .
Why don't you see this behavior due to what doc says for System.nanoTime() :
This method can only be used to measure elapsed time and is not related to any other concept of system or wall time. The return value is nanoseconds from some fixed but arbitrary start time [emphasis mine].
As to whether this is a mistake in Timer, perhaps ...
Note that unlike ScheduledExecutorService , a Timer supports absolute time, and perhaps this explains its use of System.currentTimeMillis() ; In addition, Timer exists since Java 1.3, and System.nanoTime() only appears in 1.5.
But the consequence of using System.currentTimeMillis() is that Timer sensitive to system date / time ... And this is not described in javadoc.
fge
source share