Class Clock


  • public class Clock
    extends Object
    • Constructor Detail

      • Clock

        public Clock()
    • Method Detail

      • getMonotonicTime

        public static java.time.Instant getMonotonicTime()
        Returns current monotonic time since Unix Epoch `00:00:00 UTC on 1970-01-01`.

        Returned timespec is passing machine precision and range of the underlying native API.

        Monotonic time shall be used for high-performance measurements of durations, since the underlying OS shall support fast calls.

        Note that currentNanos() and getMonotonicNanos() perform much better than this method, since they only return one long nanosecond value since module startup.
        The implementation of this method needs to write two long values into an array.

        See Also:
        getMonotonicStartupTime(), currentNanos(), getMonotonicNanos(), getWallClockTime()
      • getWallClockTime

        public static java.time.Instant getWallClockTime()
        Returns current wall-clock real-time since Unix Epoch `00:00:00 UTC on 1970-01-01`.

        Returned Instant is passing machine precision and range of the underlying native API.

        Wall-Clock time shall be used for accurate measurements of the actual time only, since the underlying OS unlikely supports fast calls.

        See Also:
        getMonotonicStartupTime(), currentNanos(), getMonotonicNanos(), getMonotonicTime()
      • currentNanos

        public static long currentNanos()
        Returns current monotonic nanoseconds since start of this application.

        Monotonic time shall be used for high-performance measurements of durations, since the underlying OS shall support fast calls.

        The returned nanoseconds are counted not from Unix Epoch but start of this module, hence it lasts for 9'223'372'036 seconds or 292 years using the 64-bit type `long`.

        Method name doesn't include the term `Time` intentionally, since the returned value represent the nanoseconds duration since module start.

        See Also:
        getMonotonicStartupTime(), getMonotonicNanos()
      • getMonotonicNanos

        public static java.time.Instant getMonotonicNanos()
        Returns the Instant presentation of monotonic currentNanos().

        Monotonic time shall be used for high-performance measurements of durations, since the underlying OS shall support fast calls.

        The returned nanoseconds are counted not from Unix Epoch but start of this module, hence it lasts for 9'223'372'036 seconds or 292 years using the 64-bit type `long`.

        Method name doesn't include the term `Time` intentionally, since the returned value represent the nanoseconds duration since module start.

        See Also:
        getMonotonicStartupTime(), currentNanos()