@FunctionalInterface public interface TimeProvider
Implementations typically delegate to the operating system clock, so the value returned can
move backwards if the wall clock is corrected. Key implementations include
PosixTimeProvider and SystemTimeProvider. The PosixTimeProvider is often
preferred for its enhanced speed, accuracy and stability, though it relies on native code and thus
may have platform specific dependencies.
This interface is crucial in contexts where precise time measurements are vital, such as in performance monitoring, timestamping events, or handling time-sensitive operations.
Use UniqueMicroTimeProvider if monotonic timestamps are required.
PosixTimeProvider,
SystemTimeProvider| Modifier and Type | Method and Description |
|---|---|
default long |
currentTimeMicros()
Retrieves the current time in microseconds.
|
long |
currentTimeMillis()
Retrieves the current time in milliseconds.
|
default long |
currentTimeNanos()
Retrieves the current time in nanoseconds.
|
long currentTimeMillis()
This method returns the current time with millisecond precision, measured from the Unix epoch (00:00:00 UTC on 1 January 1970). Implementations must guarantee thread-safe access.
default long currentTimeMicros()
throws IllegalStateException
This default implementation offers microsecond precision by scaling the millisecond value from
currentTimeMillis() by a factor of 1000. Implementations may override this for higher
accuracy if available.
IllegalStateException - if the time value cannot be accurately determined or converteddefault long currentTimeNanos()
throws IllegalStateException
This default method provides nanosecond precision by further scaling the microsecond value
from currentTimeMicros() by 1000. Implementations may provide more precise or direct
measurements if their underlying system supports it.
IllegalStateException - if the time value cannot be accurately determined or convertedCopyright © 2026 Chronicle Software Ltd. All rights reserved.