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.Runnable
Provides 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
-
-
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 long
interval()
TimeService
interval(long interval)
void
run()
boolean
running()
TimeService
start()
TimeService
stop()
long
timestamp()
Returns the timestamp (ns).java.lang.String
toString()
-
-
-
Field Detail
-
timer
protected TimeScheduler timer
-
task
protected java.util.concurrent.Future<?> task
-
interval
protected long interval
-
timestamp
protected volatile long timestamp
-
lock
protected final java.util.concurrent.locks.Lock lock
-
-
Constructor Detail
-
TimeService
public TimeService(TimeScheduler timer)
-
TimeService
public TimeService(TimeScheduler timer, long interval)
-
-
Method Detail
-
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
public TimeService interval(long interval)
-
running
public boolean running()
-
start
public TimeService start()
-
stop
public TimeService stop()
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-