public static final class TimeSource.NanoTimeSource extends TimeSource
System.nanoTime()
.
Epoch time is initialized using TimeSource.CurrentTimeSource
, and then
calculated as the elapsed number of nanoseconds as measured by this
implementation.TimeSource.CurrentTimeSource, TimeSource.NanoTimeSource, TimeSource.SimTimeSource
CURRENT_TIME, NANO_TIME
Constructor and Description |
---|
NanoTimeSource() |
Modifier and Type | Method and Description |
---|---|
long |
convertDelay(TimeUnit fromUnit,
long value,
TimeUnit toUnit)
This method allows using TimeSource with APIs that require providing just plain time intervals,
eg.
|
long |
getEpochTimeNs()
Return Epoch time.
|
long[] |
getTimeAndEpochNs()
Return both the source's time value and the corresponding epoch time
value.
|
long |
getTimeNs()
Return a time value, in nanosecond units.
|
void |
sleep(long ms)
Sleep according to this source's notion of time.
|
get, toString
public long getTimeNs()
TimeSource
getTimeNs
in class TimeSource
public long getEpochTimeNs()
TimeSource
getEpochTimeNs
in class TimeSource
public long[] getTimeAndEpochNs()
TimeSource
TimeSource.getTimeNs()
.getTimeAndEpochNs
in class TimeSource
TimeSource.getTimeNs()
and the
second element is TimeSource.getEpochTimeNs()
.public void sleep(long ms) throws InterruptedException
TimeSource
TimeSource.SimTimeSource
will sleep proportionally shorter, according to its multiplier.sleep
in class TimeSource
ms
- number of milliseconds to sleepInterruptedException
- when the current thread is interruptedpublic long convertDelay(TimeUnit fromUnit, long value, TimeUnit toUnit)
TimeSource
Object.wait(long)
. Values returned by this method are adjusted according to the
time source's notion of time - eg. accelerated time source provided by TimeSource.SimTimeSource
will return intervals that are proportionally shortened by the multiplier.
NOTE: converting small values may significantly affect precision of the returned values due to rounding, especially for accelerated time source, so care should be taken to use time units that result in relatively large values. For example, converting a value of 1 expressed in seconds would result in less precision than converting a value of 1000 expressed in milliseconds.
convertDelay
in class TimeSource
fromUnit
- source unitvalue
- original valuetoUnit
- target unitTimeSource.SimTimeSource
)Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.