Class MonitoredCallable<V>
- java.lang.Object
-
- net.obvj.performetrics.TimingSessionContainer
-
- net.obvj.performetrics.monitors.MonitoredCallable<V>
-
- Type Parameters:
V- the result type of method call
- All Implemented Interfaces:
Callable<V>
public class MonitoredCallable<V> extends TimingSessionContainer implements Callable<V>
A
Callablewrapper that maintains one or more counters for monitoring the time spent by the Callable'scall()method.Specify a target
Callablevia constructor, then execute thecall()method available in this wrapper. The targetCallable'scall()method will be executed and monitored.After the operation, call
printSummary()orprintDetails()to print the elapsed times orelapsedTime(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 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.
- Author:
- oswaldo.bapvic.jr
- See Also:
Counter,Counter.Type
-
-
Constructor Summary
Constructors Constructor Description MonitoredCallable(Callable<V> callable)Builds this monitored operation with a givenCallable.MonitoredCallable(Callable<V> callable, Counter.Type... types)Builds this monitored operation with a givenCallableand one or more specific counter types to be maintained.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vcall()-
Methods inherited from class net.obvj.performetrics.TimingSessionContainer
elapsedTime, elapsedTime, elapsedTime, elapsedTime, elapsedTime, elapsedTime, getAllCountersByType, getCounters, getTypes, lastSession, print, print, printDetails, printDetails, printSummary, printSummary, reset, toString, toString
-
-
-
-
Constructor Detail
-
MonitoredCallable
public MonitoredCallable(Callable<V> callable)
Builds this monitored operation with a givenCallable. All available counter types will be maintained.- Parameters:
callable- the Callable to be executed
-
MonitoredCallable
public MonitoredCallable(Callable<V> callable, Counter.Type... types)
Builds this monitored operation with a givenCallableand one or more specific counter types to be maintained.If no type is specified, then all of the available types will be maintained.
- Parameters:
callable- the Callable to be executedtypes- the counter types to be maintained with the operation
-
-