public class TimeService
extends java.lang.Object
implements java.lang.Runnable
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()
Modifier and Type | Field and Description |
---|---|
protected long |
interval |
protected java.util.concurrent.Future<?> |
task |
protected TimeScheduler |
timer |
protected long |
timestamp |
Constructor and Description |
---|
TimeService(TimeScheduler timer) |
TimeService(TimeScheduler timer,
long interval) |
Modifier and Type | Method and Description |
---|---|
long |
interval() |
TimeService |
interval(long interval) |
void |
run() |
boolean |
running() |
TimeService |
start() |
protected void |
startTask() |
TimeService |
stop() |
protected void |
stopTask() |
long |
timestamp()
Returns the timestamp (ns)
|
java.lang.String |
toString() |
protected TimeScheduler timer
protected volatile java.util.concurrent.Future<?> task
protected long interval
protected volatile long timestamp
public TimeService(TimeScheduler timer)
public TimeService(TimeScheduler timer, long interval)
public long timestamp()
System.nanoTime()
(ns)public long interval()
public TimeService interval(long interval)
public boolean running()
public TimeService start()
public TimeService stop()
public void run()
run
in interface java.lang.Runnable
public java.lang.String toString()
toString
in class java.lang.Object
protected void startTask()
protected void stopTask()
Copyright © 1998-2020 Red Hat. All Rights Reserved.