|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jmonit.Probe org.jmonit.Stopwatch
public class Stopwatch
a Stopwatch is used to evaluate the time consumed by a thread to execute some process. There is two way to use a Stopwatch :
start(Monitor)
method to create a new instance.
The returned object is not thread-safe and must be created on every thread
that execute the code to be monitored.monitor.getFeature(Stopwatch.class)
. In such case, the
Stopwatch object can be reused, and can also be obtained from another block
of code. It internally uses a threadLocale to associate the running Stopwatch
with the current active thread.
In both case, the monitored application MUST allways stop(boolean)
or
cancel()
even when an error occurs. For this reason, a
try/catch
is highly recommended.
If not followed, this requirement will introduce zombie threads in
Concurrency
and invalid performance statistics.
You will also get warning in logs for zombie Stopwatches.
Constructor Summary | |
---|---|
Stopwatch()
Default constructor. |
|
Stopwatch(Monitor monitor)
Constructor |
Method Summary | |
---|---|
void |
cancel()
Cancel monitoring. |
protected void |
finalize()
Monitored application should use a try/finally block to
ensure on of stop() or cancel() method is invoked, even
when an exception occurs. |
protected void |
fireMonitoringEvent(MonitoringEvent event)
|
long |
getElapsedTime()
|
boolean |
isPaused()
|
boolean |
isStarted()
|
boolean |
isStoped()
|
protected long |
nanotime()
Returns the current value of the most precise available system timer, in nanoseconds. |
void |
pause()
Temporary stop the Stopwatch. |
void |
resume()
Resume the Stopwatch after a pause. |
void |
start()
Start monitoring the process. |
static Stopwatch |
start(Monitor monitor)
Start a new Stopwatch to evaluate time consumed to execute some processing. |
long |
stop()
Stop monitoring the process. |
long |
stop(boolean canceled)
Convenience method to stop or cancel a Stopwatch depending on success of monitored operation |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Stopwatch(Monitor monitor)
monitor
- monitor that gets the elapsed time to be monitoredpublic Stopwatch()
Method Detail |
---|
public static Stopwatch start(Monitor monitor)
monitor
- the monitor used to gather the computed execution time
public void cancel()
In some circumstances you want to monitor time elapsed from early stage of computation, and discover latter if the computed data is relevant. For example, monitoring a messaging system, but beeing interested only by some types of messages. In such case, a Stopwatch can be started early and canceled when the application is able to determine it's relevancy.
In any way, the probe will still report thread concurrency even if canceled.
cancel
in class Probe
public long getElapsedTime()
getElapsedTime
in class Probe
public void pause()
pause
in class Probe
public void resume()
resume
in class Probe
public void start()
start
in class Probe
protected void fireMonitoringEvent(MonitoringEvent event)
public long stop(boolean canceled)
stop
in class Probe
canceled
-
public long stop()
start(Monitor)
cannot be re-used after stopped has been called.
stop
in class Probe
protected void finalize()
Monitored application should use a try/finally
block to
ensure on of stop()
or cancel()
method is invoked, even
when an exception occurs. To avoid Stopwatches to keep running if the
application didn't follow this recommandation, the finalizer is used to
cancel the Stopwatch and will log a educational warning.
finalize
in class java.lang.Object
Object.finalize()
protected long nanotime()
System.nanoTime()
public boolean isStarted()
true
if the Stopwatch has been startedpublic boolean isStoped()
true
if the Stopwatch has been stoppedpublic boolean isPaused()
true
if the Stopwatch has been paused
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |