Package io.opentelemetry.sdk.common
Interface Clock
-
@ThreadSafe public interface ClockInterface for getting the current time.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ClockgetDefault()Returns a defaultClockwhich reads from system time.longnanoTime()Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.longnow()Returns the current epoch timestamp in nanos from this clock.
-
-
-
Method Detail
-
getDefault
static Clock getDefault()
Returns a defaultClockwhich reads from system time.
-
now
long now()
Returns the current epoch timestamp in nanos from this clock. This timestamp should only be used to compute a current time. To compute a duration, timestamps should always be obtained usingnanoTime(). For example, this usage is correct.long startNanos = clock.nanoTime(); // Spend time... long durationNanos = clock.nanoTime() - startNanos;This usage is NOT correct.
long startNanos = clock.now(); // Spend time... long durationNanos = clock.now() - startNanos;
-
nanoTime
long nanoTime()
Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.
-
-