public class TimeService extends Object implements 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 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)
|
String |
toString() |
protected TimeScheduler timer
protected volatile 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()
protected void startTask()
protected void stopTask()
Copyright © 2020 JBoss, a division of Red Hat. All rights reserved.