public enum PosixTimeProvider extends Enum<PosixTimeProvider> implements TimeProvider
This provider interfaces directly with the native method clock_gettime
to fetch nanosecond precision wall-clock time on platforms that support it. It is
important to note that this time provider relies on native system calls, thus is
platform-dependent. It is typically more accurate and has finer resolution than
standard Java time providers.
| Enum Constant and Description |
|---|
INSTANCE |
| Modifier and Type | Method and Description |
|---|---|
long |
currentTimeMicros()
Returns the current time in microseconds.
|
long |
currentTimeMillis()
Returns the current time in milliseconds using the standard Java system clock.
|
long |
currentTimeNanos()
Returns the current time in nanoseconds.
|
static PosixTimeProvider |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static PosixTimeProvider[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final PosixTimeProvider INSTANCE
public static PosixTimeProvider[] values()
for (PosixTimeProvider c : PosixTimeProvider.values()) System.out.println(c);
public static PosixTimeProvider valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic long currentTimeMillis()
currentTimeMillis in interface TimeProviderpublic long currentTimeMicros()
throws IllegalStateException
This method provides microsecond precision by dividing the nanosecond value by 1000.
currentTimeMicros in interface TimeProviderIllegalStateException - if the time cannot be determined or convertedpublic long currentTimeNanos()
This method directly calls the native clock_gettime function, providing
highly precise and accurate nanosecond resolution time. It uses ClockId.CLOCK_REALTIME
for fetching the current time.
currentTimeNanos in interface TimeProviderIllegalStateException - if the native call failsCopyright © 2024. All rights reserved.