public class UniqueMicroTimeProvider extends Object implements TimeProvider
TimeProvider implementation that ensures unique timestamps across threads within a single process.
It provides time in milliseconds, microseconds, and nanoseconds while ensuring that the time value is unique
even across rapid successive calls.
This implementation is particularly useful in environments where unique time stamps are critical and the application might request them at a high rate.
Each call spins in a compare-and-set loop. After a failed attempt the code
invokes Jvm.nanoPause() as a short back-off before retrying. This
reduces contention when multiple threads compete to update the timestamp.
See the white paper "Unique IDs at 10 M/s" at https://chronicle.software/wp-content/uploads/Unique-IDs-at-10M_s.pdf for background on the algorithm.
| Modifier and Type | Field and Description |
|---|---|
static UniqueMicroTimeProvider |
INSTANCE |
| Constructor and Description |
|---|
UniqueMicroTimeProvider()
Constructs a new UniqueMicroTimeProvider.
|
| Modifier and Type | Method and Description |
|---|---|
long |
currentTimeMicros()
Retrieves the current time in microseconds, ensuring uniqueness across threads.
|
long |
currentTimeMillis()
Retrieves the current time in milliseconds, ensuring uniqueness across threads.
|
long |
currentTimeNanos()
Retrieves the current time in nanoseconds, ensuring uniqueness across threads.
|
UniqueMicroTimeProvider |
provider(TimeProvider provider)
Sets the underlying time provider for this instance and initialises the last time value.
|
public static final UniqueMicroTimeProvider INSTANCE
public UniqueMicroTimeProvider()
This constructor initialises the provider with zero. Instances are typically used for testing as the class maintains the last issued time.
public UniqueMicroTimeProvider provider(TimeProvider provider)
provider - delegate provider, not nullpublic long currentTimeMillis()
currentTimeMillis in interface TimeProviderpublic long currentTimeMicros()
currentTimeMicros in interface TimeProviderpublic long currentTimeNanos()
currentTimeNanos in interface TimeProviderCopyright © 2026 Chronicle Software Ltd. All rights reserved.