Timer
uses System.currentTimeMillis()
, which represents wall clock time and should never be used for checking relative times such as determining how long something took to run or, in this case, how long to delay before executing a task. System.currentTimeMillis()
is affected by things like automatic adjustments to the system clock or even manually changing the system clock. As such, if you call it twice and check the difference between the times you get, you can even get a negative number.
System.nanoTime()
, on the other hand, is specifically intended for measuring elapsed time and is what should be used for this sort of thing.