Package org.agrona.concurrent
Class CachedNanoClock
java.lang.Object
org.agrona.concurrent.CachedNanoClock
- All Implemented Interfaces:
NanoClock
A
NanoClock that caches a timestamp which can be updated with update(long).
Instances are threadsafe with the read being volatile.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance(long nanos) Advance the value of the timestamp in with release ordered semantics.longnanoTime()The number of ticks in nanoseconds the clock has advanced since starting.voidupdate(long timeNs) Update the value of the timestamp with release memory ordered semantics.
-
Field Details
-
timeNs
protected volatile long timeNsTime in nanoseconds.
-
-
Constructor Details
-
CachedNanoClock
public CachedNanoClock()Create a new instance.
-
-
Method Details
-
nanoTime
public long nanoTime()The number of ticks in nanoseconds the clock has advanced since starting.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.
-
update
public void update(long timeNs) Update the value of the timestamp with release memory ordered semantics.- Parameters:
timeNs- value to update the timestamp.
-
advance
public void advance(long nanos) Advance the value of the timestamp in with release ordered semantics.- Parameters:
nanos- to advance the timestamp.
-