Class Stopwatch

java.lang.Object
net.bull.javamelody.Stopwatch
All Implemented Interfaces:
AutoCloseable

public class Stopwatch extends Object implements AutoCloseable
Stopwatch to record execution times of a piece of code in the services statistics. (To monitor whole methods, see MonitoringSpringInterceptor, MonitoringInterceptor or MonitoringProxy.)
Author:
Emeric Vernat
  • Constructor Details

    • Stopwatch

      public Stopwatch(String stopwatchName)
      Starts a stopwatch (must always be used in try-with-resource):
       try (Stopwatch stopwatch = new Stopwatch("nameyouwant")) {
           // your code
       }
       
      Parameters:
      stopwatchName - Whatever name you want to display in the statistics
  • Method Details

    • getName

      public String getName()
      Returns:
      name of the stopwatch.
    • getDuration

      public long getDuration()
      Returns:
      duration until now or until stop of the stopwatch.
    • isClosed

      public boolean isClosed()
      Returns:
      already stopped ?
    • close

      public void close()
      Stops the stopwatch.
      Specified by:
      close in interface AutoCloseable