Timer (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.util, class: Timer

Package org.apache.hadoop.util

# Class Timer

java.lang.Object
org.apache.hadoop.util.Timer

@Private @Unstable public class Timer extends Object
Utility methods for getting the time and computing intervals. It has the same behavior as {`Time`}, with the exception that its functions can be overridden for dependency injection purposes.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Timer()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `monotonicNow()`
  Current time from some arbitrary time base in the past, counting in milliseconds, and not affected by settimeofday or similar system clock changes.
  `long`
  `monotonicNowNanos()`
  Same as `monotonicNow()` but returns its result in nanoseconds.
  `long`
  `now()`
  Current system time.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Timer

    public Timer()

- ## Method Details

  - ### now

    public long now()
    Current system time. Do not use this to calculate a duration or interval to sleep, because it will be broken by settimeofday. Instead, use monotonicNow.
    Returns:
      current time in msec.

  - ### monotonicNow

    public long monotonicNow()
    Current time from some arbitrary time base in the past, counting in milliseconds, and not affected by settimeofday or similar system clock changes. This is appropriate to use when computing how much longer to wait for an interval to expire.
    Returns:
      a monotonic clock that counts in milliseconds.

  - ### monotonicNowNanos

    public long monotonicNowNanos()
    Same as `monotonicNow()` but returns its result in nanoseconds. Note that this is subject to the same resolution constraints as `System.nanoTime()`.
    Returns:
      a monotonic clock that counts in nanoseconds.