Class StopWatch


  • public final class StopWatch
    extends Object
    A very simple stop watch.

    This implementation is not thread safe and can only time one task at any given time.

    • Constructor Detail

      • StopWatch

        public StopWatch()
        Starts the stop watch
      • StopWatch

        public StopWatch​(long timeMillis)
        Starts the stop watch from the given timestamp
      • StopWatch

        public StopWatch​(boolean start)
        Creates the stop watch
        Parameters:
        start - whether it should start immediately
    • Method Detail

      • restart

        public void restart()
        Starts or restarts the stop watch
      • isStarted

        public boolean isStarted()
        Whether the watch is started
      • taken

        public long taken()
        Returns the time taken in millis.
        Returns:
        time in millis, or 0 if not started yet.
      • takenAndRestart

        public long takenAndRestart()
        Returns the time taken in millis and restarts the timer.
        Returns:
        time in millis, or 0 if not started yet.
      • elapsedMillisSince

        @Deprecated
        public static long elapsedMillisSince​(long start)
        Deprecated.
        Utility method to provide the elapsed time using milliseconds since epoch. This serves as an alternative for the former constructor based on a Date argument. This should be used only when converting old code that relies on that constructor as it can provide incorrect measurements in rare circumstances
        Parameters:
        start - the timestamp in milliseconds since epoch
        Returns:
        the elapsed time in milliseconds