Package org.jgroups.util
Class TimeService
- java.lang.Object
-
- org.jgroups.util.TimeService
-
- All Implemented Interfaces:
java.lang.Runnable
public class TimeService extends java.lang.Object implements java.lang.RunnableProvides a coarse grained time service. Registers a timer task which calls and cachesSystem.nanoTime()and returns the cached value. This is way faster than callingSystem.nanoTime()many times, e.g. for each received message. The granularity (interval) can be chosen by the user. Note that use of values returned bytimestamp()needs to obey the same rules as forSystem.nanoTime()- Since:
- 3.5
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected longintervalprotected java.util.concurrent.Future<?>taskprotected TimeSchedulertimerprotected longtimestamp
-
Constructor Summary
Constructors Constructor Description TimeService(TimeScheduler timer)TimeService(TimeScheduler timer, long interval)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longinterval()TimeServiceinterval(long interval)voidrun()booleanrunning()TimeServicestart()TimeServicestop()longtimestamp()Returns the timestamp (ns)java.lang.StringtoString()
-
-
-
Field Detail
-
timer
protected TimeScheduler timer
-
task
protected volatile java.util.concurrent.Future<?> task
-
interval
protected long interval
-
timestamp
protected volatile long timestamp
-
-
Constructor Detail
-
TimeService
public TimeService(TimeScheduler timer)
-
TimeService
public TimeService(TimeScheduler timer, long interval)
-
-
Method Detail
-
timestamp
public long timestamp()
Returns the timestamp (ns)- Returns:
- the result of the last call to
System.nanoTime()(ns)
-
interval
public long interval()
-
interval
public TimeService interval(long interval)
-
running
public boolean running()
-
start
public TimeService start()
-
stop
public TimeService stop()
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-