I used System.nanoTime () between threads and processes. On one machine, it grows globally and monotonously (with the exception of multi-node Windows XP)
If you see a negative difference, this is most likely an error in your code.
You can see nanoTime () between machines, but you need to adjust the difference and drift between the clocks. (And you can get great very negative results if you don't make this correction)
the start time is set by the process on another machine, and the difference is calculated on another machine.
Between machines you need either
- use System.currentTimjeMillis (), which is usually millisecond accurate with NTP.
- use System.nanoTime () to travel back and forth, that is, send a message from A ro B, and the other back to A. The half-time of the trip can be estimated from this.
- use System.nanoTime () not for time, but for jitter detection. This suggests that most of the delay time is acceptable (say, 10 to 100 microseconds), but sometimes it is much higher than usual. I use this class to help detect jitter. Runningminimum
If you are only interested in multi-million delays, I would use currentTimeMillis ()
source share