Class StopWatch

java.lang.Object
org.springframework.util.StopWatch

public class StopWatch extends Object
Simple stop watch, allowing for timing of a number of tasks, exposing total running time and running time for each named task.

Conceals use of System.nanoTime(), improving the readability of application code and reducing the likelihood of calculation errors.

Note that this object is not designed to be thread-safe and does not use synchronization.

This class is normally used to verify performance during proof-of-concept work and in development, rather than as part of production applications.

As of Spring Framework 5.2, running time is tracked and reported in nanoseconds.

Since:
May 2, 2001
Author:
Rod Johnson, Juergen Hoeller, Sam Brannen
  • Constructor Details

    • StopWatch

      public StopWatch()
      Construct a new StopWatch.

      Does not start any task.

    • StopWatch

      public StopWatch(String id)
      Construct a new StopWatch with the given id.

      The id is handy when we have output from multiple stop watches and need to distinguish between them.

      Does not start any task.

      Parameters:
      id - identifier for this stop watch
  • Method Details