In Java System.nanoTime()
's monotonic implementation on Linux relies on the fact that CLOCK_MONOTONIC
is available on the OS. If it's not available, it falls back to gettimeofday
which can result in getting a negative time interval when the interval is measured using nanoTime
. For instance, the following test might fail.
long t1 = System.nanoTime();
long t2 = System.nanoTime();
assert t2 >= t1
In what cases CLOCK_MONOTONIC
might not be available on a server? Is it reasonable to assume that CLOCK_MONOTONIC
clock is available on all modern Linux servers?