|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.StopWatch
Simple stop watch, allowing for timing of a number of tasks, exposing total running time and running time for each named task. Conceals use of System.currentTimeMillis(), improving the readability of application code and reducing the likelihood of calculation errors.
Note that this object is not designed to be threadsafe, and does not use synchronization or threading. Therefore it is safe to invoke it from EJBs.
This class is normally used to verify performance during proof-of-concepts and in development, rather than as part of production applications.
Nested Class Summary | |
static class |
StopWatch.TaskInfo
Inner class to hold data about one task executed within the stopwatch |
Constructor Summary | |
StopWatch()
Construct a new stop watch. |
|
StopWatch(java.lang.String id)
Construct a new stop watch with the given id. |
Method Summary | |
boolean |
getKeepTaskList()
|
long |
getLastInterval()
Returns the time taken by the last operation. |
int |
getTaskCount()
Returns the number of tasks timed. |
StopWatch.TaskInfo[] |
getTaskInfo()
Returns an array of the data for tasks performed. |
long |
getTotalTime()
Returns the total time in milliseconds for all tasks. |
double |
getTotalTimeSecs()
Returns the total time in seconds for all tasks. |
boolean |
isRunning()
Returns whether the stopwatch is currently running. |
java.lang.String |
prettyPrint()
Returns a string with a table describing all tasks performed. |
void |
setKeepTaskList(boolean keepTaskList)
Determines whether TaskInfo array is built over time. |
java.lang.String |
shortSummary()
Returns a short description of the total running time. |
void |
start(java.lang.String task)
Start a named task. |
void |
stop()
Stop the current task. |
java.lang.String |
toString()
Returns an informative string describing all tasks performed For custom reporting, call getTaskInfo() and use the task info directly. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public StopWatch()
public StopWatch(java.lang.String id)
id
- identifier for this stop watch.
Handy when we have output from multiple stop watches and need to distinguish between them.Method Detail |
public void setKeepTaskList(boolean keepTaskList)
keepTaskList
- public boolean getKeepTaskList()
public void start(java.lang.String task) throws java.lang.IllegalStateException
task
- name of the task to start
java.lang.IllegalStateException
public void stop() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public long getTotalTime()
public long getLastInterval() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public double getTotalTimeSecs()
public int getTaskCount()
public StopWatch.TaskInfo[] getTaskInfo()
public boolean isRunning()
public java.lang.String shortSummary()
public java.lang.String prettyPrint()
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |