All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.bull.javamelody.Stopwatch Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package net.bull.javamelody;

import net.bull.javamelody.internal.model.Counter;

/**
 * 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
 */
public class Stopwatch implements AutoCloseable {
	private static final Counter SERVICES_COUNTER = MonitoringProxy.getServicesCounter();

	/**
	 * Starts a stopwatch (must always be used in try-with-resource):
	 * 
	 * try (Stopwatch stopwatch = new Stopwatch("nameyouwant")) {
	 *     // your code
	 * }
	 * 
* @param stopwatchName Whatever name you want to display in the statistics */ public Stopwatch(String stopwatchName) { super(); SERVICES_COUNTER.bindContextIncludingCpu(stopwatchName); } /** * Stops the stopwatch. */ @Override public void close() throws Exception { SERVICES_COUNTER.addRequestForCurrentContext(false); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy