V - the result type of method callpublic class MonitoredCallable<V> extends MonitoredOperation implements Callable<V>
A Callable wrapper that maintains one or more counters for monitoring the time
spent by the Callable's call() method.
Specify a target Callable via constructor, then execute the call()
method available in this wrapper. The target Callable's call() method
will be executed and monitored. After the operation, call
printSummary(System.out) or printDetails(System.out) to print the
elapsed times to the system console or elapsedTime(Counter.Type), to retrieve
the elapsed time duration for a particular counter. E.g.:
double cpuTimeNanos = monitoredRunnable.elapsedTime(Counter.Type.CPU_TIME, TimeUnit.NANOSECONDS);
By default, all available counter types will be measured, if no specific counter types are passed to the constructor. If required, an additional constructor may be used to set up one or more specific counters to be maintained. E.g.:
new MonitoredCallable(callable); // maintains all available counter types new MonitoredCallable(callable, Counter.Type.WALL_CLOCK_TIME); // wall-clock time only
For a list of available counters, refer to Counter.Type.
Note: This class is not thread-safe. In a multi-thread context, different instances must be created for each thread.
Counter,
Counter.Type| Constructor and Description |
|---|
MonitoredCallable(Callable<V> targetCallable)
Builds this monitored operation with a given
Callable. |
MonitoredCallable(Callable<V> targetCallable,
Counter.Type... types)
Builds this monitored operation with a given
Callable and one or more specific
counter types to be maintained. |
| Modifier and Type | Method and Description |
|---|---|
V |
call()
See
Callable.call(). |
elapsedTime, elapsedTime, elapsedTime, getAllCountersByType, getCounters, printDetails, printDetails, printSummary, printSummary, resetpublic MonitoredCallable(Callable<V> targetCallable)
Callable. All available counter
types will be maintained.targetCallable - the Callable to be executedpublic MonitoredCallable(Callable<V> targetCallable, Counter.Type... types)
Callable and one or more specific
counter types to be maintained.targetCallable - the Callable to be executedtypes - the counter types to be maintained with the operationCopyright © 2021. All rights reserved.