Package org.apache.hadoop.util
Class Time
java.lang.Object
org.apache.hadoop.util.Time
Utility methods for getting the time and computing intervals.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatTime(long millis) Convert time in millisecond to human readable format.static longGet the current UTC time in milliseconds.static longCurrent time from some arbitrary time base in the past, counting in milliseconds, and not affected by settimeofday or similar system clock changes.static longSame asmonotonicNow()but returns its result in nanoseconds.static longnow()Current system time.
-
Constructor Details
-
Time
public Time()
-
-
Method Details
-
now
public static 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 static 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. This function can return a negative value and it must be handled correctly by callers. See the documentation of System#nanoTime for caveats.- Returns:
- a monotonic clock that counts in milliseconds.
-
monotonicNowNanos
public static long monotonicNowNanos()Same asmonotonicNow()but returns its result in nanoseconds. Note that this is subject to the same resolution constraints asSystem.nanoTime().- Returns:
- a monotonic clock that counts in nanoseconds.
-
formatTime
Convert time in millisecond to human readable format.- Parameters:
millis- millisecond.- Returns:
- a human readable string for the input time
-
getUtcTime
public static long getUtcTime()Get the current UTC time in milliseconds.- Returns:
- the current UTC time in milliseconds.
-