Class Stopwatch

java.lang.Object
com.stripe.util.Stopwatch

public class Stopwatch extends Object
This class provides a set of methods and properties that can be used to accurately measure elapsed time.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the Stopwatch class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the total elapsed time measured by the current instance.
    static long
    Gets the current timestamp with the highest precision available.
    boolean
    Gets a value indicating whether the Stopwatch timer is running.
    void
    Stops time interval measurement and resets the elapsed time to zero.
    void
    Stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time.
    void
    Starts, or resumes, measuring elapsed time for an interval.
    static Stopwatch
    Initializes a new Stopwatch instance, sets the elapsed time property to zero, and starts measuring elapsed time.
    void
    Stops measuring elapsed time for an interval.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Stopwatch

      public Stopwatch()
      Initializes a new instance of the Stopwatch class.
  • Method Details

    • start

      public void start()
      Starts, or resumes, measuring elapsed time for an interval.
    • startNew

      public static Stopwatch startNew()
      Initializes a new Stopwatch instance, sets the elapsed time property to zero, and starts measuring elapsed time.
      Returns:
      a Stopwatch that has just begun measuring elapsed time
    • stop

      public void stop()
      Stops measuring elapsed time for an interval.
    • reset

      public void reset()
      Stops time interval measurement and resets the elapsed time to zero.
    • restart

      public void restart()
      Stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time.
    • isRunning

      public boolean isRunning()
      Gets a value indicating whether the Stopwatch timer is running.
      Returns:
      true if the Stopwatch instance is currently running and measuring elapsed time for an interval; otherwise, false
    • getElapsed

      public Duration getElapsed()
      Gets the total elapsed time measured by the current instance.
      Returns:
      a Duration representing the total elapsed time measured by the current instance
    • getTimestamp

      public static long getTimestamp()
      Gets the current timestamp with the highest precision available. This should use a monotonic clock whenever possible.
      Returns:
      a long integer representing the current timestamp