org.apache.hadoop.util

## 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 Summary

    Constructors
    Constructor and Description
    `StopWatch()`
    `StopWatch(org.apache.hadoop.util.Timer timer)` Used for tests to be able to create a StopWatch which does not follow real time.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `boolean` | `isRunning()` The method is used to find out if the StopWatch is started.
    `long` | `now()`
    `long` | `now(TimeUnit timeUnit)`
    `StopWatch` | `reset()` Reset elapsed time to zero and make the state of stopwatch stop.
    `StopWatch` | `start()` Start to measure times and make the state of stopwatch running.
    `StopWatch` | `stop()` Stop elapsed time and make the state of stopwatch stop.
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### StopWatch

          public StopWatch()

    - #### StopWatch

          public StopWatch(org.apache.hadoop.util.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 Detail

    - #### 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)

      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 `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.