org.perf4j
Class TimedRunnable

java.lang.Object
  extended by org.perf4j.TimedRunnable
All Implemented Interfaces:
Serializable, Runnable

public class TimedRunnable
extends Object
implements Runnable, Serializable

This helper wrapper class can be used to add timing statements to an existing Runnable instance, logging how long it takes for the run method to execute. Note that instances of this class are only serializable if the wrapped Runnable is serializable.

Author:
Alex Devine
See Also:
Serialized Form

Constructor Summary
TimedRunnable(Runnable task, LoggingStopWatch stopWatch)
          Wraps the existing Runnable in order to time its run method.
 
Method Summary
 LoggingStopWatch getStopWatch()
          Gets the LoggingStopWatch that will be used to time the run method execution.
 Runnable getWrappedTask()
          Gets the Runnable task that is wrapped by this TimedRunnable.
 void run()
          Executes the run method of the underlying task, using the LoggingStopWatch to track the execution time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimedRunnable

public TimedRunnable(Runnable task,
                     LoggingStopWatch stopWatch)
Wraps the existing Runnable in order to time its run method.

Parameters:
task - The existing Runnable whose run method is to be timed and executed. May not be null.
stopWatch - The LoggingStopWatch to use to time the run method execution. Note that this stop watch should already have its tag and message set to what should be logged when the task is run. May not be null.
Method Detail

getWrappedTask

public Runnable getWrappedTask()
Gets the Runnable task that is wrapped by this TimedRunnable.

Returns:
The wrapped Runnable whose execution time is to be logged.

getStopWatch

public LoggingStopWatch getStopWatch()
Gets the LoggingStopWatch that will be used to time the run method execution.

Returns:
The LoggingStopWatch to use to log execution time.

run

public void run()
Executes the run method of the underlying task, using the LoggingStopWatch to track the execution time.

Specified by:
run in interface Runnable


Copyright © 2008-2011 perf4j.org. All Rights Reserved.