It depends on what you want to measure.
Do you want to keep track of your asynchronous executions? Then you
should use an instrumented execution service
(
http://metrics.dropwizard.io/4.0.0/apidocs/com/codahale/metrics/InstrumentedExecutorService.html).
Do you want to know how long it takes before the method finishes
after you started it? Then you can use the
update method
on timer. An example looks like this:
public void methodRequest() {
static long start = System.nanoTime();
executor.schedule(new Runnable() {
public void run() {
// ... do some work ...
responses.update(System.nanoTime() - start, NANOSECONDS);
}
});
}
Do you want to know how long the method is running (excluding
waiting time)? Then just move the entire measurement in its original
form (using the
time method) into the asynchronously run
task.
Do you want to measure the wait time before an async job is picked
up? Then you should extend the instrumented executor service to also
measure wait time (again using the
update method).
Kind regards,
Erik.
--
Erik van Oosten
http://day-to-day-stuff.blogspot.nl/
Op 24-01-18 om 08:02 schreef Shehan
Perera: