On 10.07.2017 11:44, Juan Barani wrote:
Just to add something else to the scenario, can it happen that due to
NTP adjustments in the servers then System.currentTimeMillis() returns
a smaller value than before? May it be that using System.nanoTime()
this problem does not appear?
I guess nanoTime() should indeed be used (not related to system or
wall-clock time within a VM):
"Returns the current value of the running Java Virtual Machine's
high-resolution time source, in nanoseconds.
This method can only be used to measure elapsed time and is not
related to any other notion of system or wall-clock time. The value
returned represents nanoseconds since some fixed but arbitrary
/origin/ time (perhaps in the future, so values may be negative).
The same origin is used by all invocations of this method in an
instance of a Java virtual machine; other virtual machine instances
are likely to use a different origin.
This method provides nanosecond precision, but not necessarily
nanosecond resolution (that is, how frequently the value changes) -
no guarantees are made except that the resolution is at least as
good as that of |currentTimeMillis()|
<http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#currentTimeMillis%28%29>.
Differences in successive calls that span greater than approximately
292 years (2^63 nanoseconds) will not correctly compute elapsed time
due to numerical overflow.
The values returned by this method become meaningful only when the
difference between two such values, obtained within the same
instance of a Java virtual machine, is computed."