public class MonitoredRunnable extends MonitoredOperation implements Runnable
A Runnable wrapper that maintains one or more counters for monitoring the time
spent by the Runnable's run() method.
Specify a target Runnable via constructor, then execute the run()
method available in this wrapper. The target Runnable's run() method
will be executed and monitored.
After the operation, call printSummary() or printDetails() to print the
elapsed times or elapsedTime(Counter.Type), to retrieve the elapsed time
duration for a particular counter. E.g.:
Duration cpuTime = monitoredRunnable.elapsedTime(Counter.Type.CPU_TIME);
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 MonitoredRunnable(runnable); // maintains all available counter types new MonitoredRunnable(runnable, 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 |
|---|
MonitoredRunnable(Runnable runnable)
Builds this monitored operation with a given
Runnable. |
MonitoredRunnable(Runnable runnable,
Counter.Type... types)
Builds this monitored operation with a given
Runnable and one or more specific
counter types to be maintained. |
| Modifier and Type | Method and Description |
|---|---|
void |
run() |
elapsedTime, elapsedTime, elapsedTime, elapsedTime, elapsedTime, elapsedTime, getAllCountersByType, getCounters, printDetails, printDetails, printSummary, printSummary, reset, toStringpublic MonitoredRunnable(Runnable runnable)
Runnable. All available counter
types will be maintained.runnable - the Runnable to be executed and profiledpublic MonitoredRunnable(Runnable runnable, Counter.Type... types)
Runnable and one or more specific
counter types to be maintained.
If no type is specified, then all of the available types will be maintained.
runnable - the Runnable to be executed and profiledtypes - the counter types to be maintained with the operationCopyright © 2021. All rights reserved.