I made a little program to test the System.currentTimeMillis (). And I have a strange result. This is my logs :
1 26-12-09 20:48:21 - [Log] lTime = 1261860501009
2 26-12-09 20:48:21 - [Log] lTime = 1261860501012
3 26-12-09 20:48:21 - [Log] lTime = 1261864899078
4 26-12-09 20:48:21 - [Log] lTime = 1261860501033
5 26-12-09 20:48:21 - [Log] lTime = 1261860501069
As you can see, there is a problem on line 3. The time millis is wrong. It should be between 1261860501012 and 1261860501033. There is an error of, roughly, 73 milli seconds.
Somebody knows where the problem come from ?
Thanks a lot
bill0ute
Edit : OS : Debian 4.0, Java : 6_17.
My code :
while (true)
setLog (System.currentTimeMillis ());
Edit : The program run on a Linux based VPS
System.currentTimeMillis()
is dependent on System clock. It looks like the system clock has been micro-corrected by an external programme, for Linux that's probably NTP.
Note you shouldn't use System.currentTimeMillis()
to measure elapsed time. It's better to use System.nanoTime()
but even that isn't guaranteed to be monotonic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With