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.SimTimeSourceCURRENT_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, toStringpublic long getTimeNs()
TimeSourcegetTimeNs in class TimeSourcepublic long getEpochTimeNs()
TimeSourcegetEpochTimeNs in class TimeSourcepublic long[] getTimeAndEpochNs()
TimeSourceTimeSource.getTimeNs().getTimeAndEpochNs in class TimeSourceTimeSource.getTimeNs() and the
second element is TimeSource.getEpochTimeNs().public void sleep(long ms)
throws InterruptedException
TimeSourceTimeSource.SimTimeSource will sleep proportionally shorter, according to its multiplier.sleep in class TimeSourcems - number of milliseconds to sleepInterruptedException - when the current thread is interruptedpublic long convertDelay(TimeUnit fromUnit, long value, TimeUnit toUnit)
TimeSourceObject.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 TimeSourcefromUnit - source unitvalue - original valuetoUnit - target unitTimeSource.SimTimeSource)Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.