public interface Clock
|Modifier and Type||Method and Description|
Current value of high resolution time source, in ns.
Wait until the wall clock reaches at least the given time.
This method abstracts the call to the JRE's
System.nanoTime() call. As with that method, the
value here is not guaranteed to be monotonically increasing, but rather a higher resolution
time source for use in the calculation of time intervals. The characteristics of the values
returned may very from JVM to JVM (or even the same JVM running on different OSes or CPUs), but
in general it should be preferred over
getTimeMillis() when calculating time differences.
Specifically for Linux on x64 architecture, the following links provide useful information about the characteristics of the value returned:
TL;DR: on modern (2.6.32+) Linux kernels with modern (AMD K8+) CPUs, the values returned by
System.nanoTime() are consistent across CPU cores *and* packages, and provide always
increasing values (although it may not be completely monotonic when the system clock is
adjusted by NTP daemons using time slew).
long waitTillTime(long targetTime)