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 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.