Created
June 12, 2012 19:00
-
-
Save ezbz/2919431 to your computer and use it in GitHub Desktop.
Creating a timer in code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inject this | |
private final MetricFactory metricFactory; | |
public MyBean(final MetricFactory metricFactory) { | |
this.metricFactory = metricFactory; | |
} | |
// Use the factory to create metrics objects like Timer or Counter: | |
final Timer timer = metricFactory.createTimer(componentName, methodName); | |
final TimerContext timerContext = timer.time(); | |
try{ | |
// do some stuff | |
finally { | |
timerContext.stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment