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 thread-safe and does not use synchronization.
This class is normally used to verify performance during proof-of-concepts and in development, rather than as part of production applications.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
StopWatch.TaskInfo | Inner class to hold data about one task executed within the stop watch. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new stop watch.
| |||||||||||
Construct a new stop watch with the given id.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the last task as a TaskInfo object.
| |||||||||||
Return the name of the last task.
| |||||||||||
Return the time taken by the last task.
| |||||||||||
Return the number of tasks timed.
| |||||||||||
Return an array of the data for tasks performed.
| |||||||||||
Return the total time in milliseconds for all tasks.
| |||||||||||
Return the total time in seconds for all tasks.
| |||||||||||
Return whether the stop watch is currently running.
| |||||||||||
Return a string with a table describing all tasks performed.
| |||||||||||
Determine whether the TaskInfo array is built over time.
| |||||||||||
Return a short description of the total running time.
| |||||||||||
Start an unnamed task.
| |||||||||||
Start a named task.
| |||||||||||
Stop the current task.
| |||||||||||
Return an informative string describing all tasks performed
For custom reporting, call
getTaskInfo() and use the task info directly. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Construct a new stop watch with the given id. Does not start any task.
id | identifier for this stop watch. Handy when we have output from multiple stop watches and need to distinguish between them. |
---|
Return the last task as a TaskInfo object.
IllegalStateException |
---|
Return the name of the last task.
IllegalStateException |
---|
Return the time taken by the last task.
IllegalStateException |
---|
Return the total time in milliseconds for all tasks.
Return the total time in seconds for all tasks.
Return a string with a table describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly.
Determine whether the TaskInfo array is built over time. Set this to "false" when using a StopWatch for millions of intervals, or the task info structure will consume excessive memory. Default is "true".
Return a short description of the total running time.
Start an unnamed task. The results are undefined if stop()
or timing methods are called without invoking this method.
IllegalStateException |
---|
Start a named task. The results are undefined if stop()
or timing methods are called without invoking this method.
taskName | the name of the task to start |
---|
IllegalStateException |
---|
Stop the current task. The results are undefined if timing
methods are called without invoking at least one pair
start()
/ stop()
methods.
IllegalStateException |
---|
Return an informative string describing all tasks performed
For custom reporting, call getTaskInfo()
and use the task info directly.