Package org.agrona.concurrent
Class OffsetEpochNanoClock
java.lang.Object
org.agrona.concurrent.OffsetEpochNanoClock
- All Implemented Interfaces:
EpochNanoClock
An accurate, zero-gc, pure-java,
EpochNanoClock that calculates an initial epoch nano time based on
System.currentTimeMillis() and then uses that offset to adjust the return value of
System.nanoTime() to the UNIX epoch.
The sample() method can be used in order to reset these initial values if your system clock gets updated.
This class can be used from multiple threads safely.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs the clock with default configuration.OffsetEpochNanoClock(int maxMeasurementRetries, long measurementThresholdNs, long resampleIntervalNs) Constructs the clock with custom configuration parameters. -
Method Summary
-
Constructor Details
-
OffsetEpochNanoClock
public OffsetEpochNanoClock()Constructs the clock with default configuration. -
OffsetEpochNanoClock
public OffsetEpochNanoClock(int maxMeasurementRetries, long measurementThresholdNs, long resampleIntervalNs) Constructs the clock with custom configuration parameters.- Parameters:
maxMeasurementRetries- the maximum number of times that this clock will attempt to re-sample the initial time values.measurementThresholdNs- the desired accuracy window for the initial clock samples.resampleIntervalNs- the desired interval before the samples are automatically recalculated. The seed recalculation enables the system to minimise clock drift if the system clock is updated.
-
-
Method Details
-
sample
public void sample()Explicitly resample the initial seeds. -
nanoTime
public long nanoTime()Time in nanoseconds since 1 Jan 1970 UTC.- Specified by:
nanoTimein interfaceEpochNanoClock- Returns:
- the number of nanoseconds since 1 Jan 1970 UTC.
-
isWithinThreshold
public boolean isWithinThreshold()Gets whether the clock sampled the initial time offset accurately.- Returns:
- true if the clock sampled the initial time offset accurately.
-