Class StopWatch

java.lang.Object
org.apache.hadoop.util.StopWatch
All Implemented Interfaces:
Closeable, AutoCloseable

public class StopWatch extends Object implements Closeable
A simplified StopWatch implementation which can measure times in nanoseconds.
  • Constructor Details

    • StopWatch

      public StopWatch()
    • StopWatch

      public StopWatch(Timer timer)
      Used for tests to be able to create a StopWatch which does not follow real time.
      Parameters:
      timer - The timer to base this StopWatch's timekeeping off of.
  • Method Details

    • isRunning

      public boolean isRunning()
      The method is used to find out if the StopWatch is started.
      Returns:
      boolean If the StopWatch is started.
    • start

      public StopWatch start()
      Start to measure times and make the state of stopwatch running.
      Returns:
      this instance of StopWatch.
    • stop

      public StopWatch stop()
      Stop elapsed time and make the state of stopwatch stop.
      Returns:
      this instance of StopWatch.
    • reset

      public StopWatch reset()
      Reset elapsed time to zero and make the state of stopwatch stop.
      Returns:
      this instance of StopWatch.
    • now

      public long now(TimeUnit timeUnit)
      now.
      Parameters:
      timeUnit - timeUnit.
      Returns:
      current elapsed time in specified timeunit.
    • now

      public long now()
      Returns:
      current elapsed time in nanosecond.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable