Package org.jgroups.util
Class TimeService
java.lang.Object
org.jgroups.util.TimeService
- All Implemented Interfaces:
Runnable
Provides a coarse grained time service. Registers a timer task which calls and caches
System.nanoTime()
and returns the cached value. This is way faster than calling System.nanoTime() many times, e.g.
for each received message. The granularity (interval) can be chosen by the user.
Note that use of values returned by timestamp() needs to obey the same rules as for System.nanoTime()
- Since:
- 3.5
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTimeService(TimeScheduler timer) TimeService(TimeScheduler timer, long interval) -
Method Summary
-
Field Details
-
timer
-
task
-
interval
protected long interval -
timestamp
protected volatile long timestamp -
lock
-
-
Constructor Details
-
TimeService
-
TimeService
-
-
Method Details
-
timestamp
public long timestamp()Returns the timestamp (ns). Because timestamp is volatile, the read will return the result of the most recent write- Returns:
- the result of the last call to
System.nanoTime()(ns)
-
interval
public long interval() -
interval
-
running
public boolean running() -
start
-
stop
-
run
public void run() -
toString
-