public class EstimatorTimeSource extends Thread implements TimeSource
This implementation uses a background thread to regularly fetch the current time from System.currentTimeMillis(). The value is cached and returned in all methods returning a time. Caching is helpful, as fetching the time includes a potentially expensive crossing of the operating system boundary (calling native, levering privilege, register swapping, ...). If you call it thousands or millions of times per second, this has a very noticeable effect. For these cases the throughput can be massively increased (100% or even 1000%).
Users of this class must be aware that all calls within the update interval will return exactly the same time. For example a Cache implementation that uses this class will have more entries with the identical incoming timestamp. This can have an effect on expiration or time-based eviction strategies like LRU.
Thread.State, Thread.UncaughtExceptionHandlerMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
EstimatorTimeSource(int updateIntervalMillis)
Creates a TimeSource with the given update interval, that uses the system time as TimeSource.
|
EstimatorTimeSource(TimeSource parentTimeSource,
int updateIntervalMillis,
TriavaLogger logger)
Creates a TimeSource with the given update interval.
|
| Modifier and Type | Method and Description |
|---|---|
long |
millis()
Returns the time in milliseconds.
|
void |
run() |
long |
seconds()
Returns the time in seconds.
|
void |
shutdown()
Shutdown the time source.
|
long |
time(TimeUnit tu)
Returns the time in the given time unit.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldpublic EstimatorTimeSource(int updateIntervalMillis)
updateIntervalMillis - Update interval, which defines the approximate precisionpublic EstimatorTimeSource(TimeSource parentTimeSource, int updateIntervalMillis, TriavaLogger logger)
parentTimeSource - The TimeSource to estimateupdateIntervalMillis - Update interval, which defines the approximate precisionlogger - A non-null triava loggerpublic void shutdown()
TimeSourceshutdown in interface TimeSourcepublic long time(TimeUnit tu)
TimeSourcetime in interface TimeSourcetu - The time unit for the return valuepublic long seconds()
TimeSourceTimeSource.time(TimeUnit)seconds in interface TimeSourcepublic long millis()
TimeSourceTimeSource.time(TimeUnit)millis in interface TimeSourceCopyright © 2018 trivago. All rights reserved.