Timer
uses System.currentTimeMillis()
to determine the next execution of a task.
However ScheduledThreadPoolExecutor
uses System.nanoTime()
.
Also nanoTime()
method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time.
System.currentTimeMillis()
is sensitive to system clock
System.nanoTime()
is not sensitive to system clock as it measures the time elapsed.
Java Documentation: System.nanoTime()
This method can only be used to measure elapsed time and is not
related to any other notion of system or wall-clock time. The value
returned represents nanoseconds since some fixed but arbitrary time
(perhaps in the future, so values may be negative).