public class

StopWatch

extends Object
java.lang.Object
   ↳ org.springframework.util.StopWatch

Class Overview

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.

Summary

Nested Classes
class StopWatch.TaskInfo Inner class to hold data about one task executed within the stop watch. 
Public Constructors
StopWatch()
Construct a new stop watch.
StopWatch(String id)
Construct a new stop watch with the given id.
Public Methods
StopWatch.TaskInfo getLastTaskInfo()
Return the last task as a TaskInfo object.
String getLastTaskName()
Return the name of the last task.
long getLastTaskTimeMillis()
Return the time taken by the last task.
int getTaskCount()
Return the number of tasks timed.
TaskInfo[] getTaskInfo()
Return an array of the data for tasks performed.
long getTotalTimeMillis()
Return the total time in milliseconds for all tasks.
double getTotalTimeSeconds()
Return the total time in seconds for all tasks.
boolean isRunning()
Return whether the stop watch is currently running.
String prettyPrint()
Return a string with a table describing all tasks performed.
void setKeepTaskList(boolean keepTaskList)
Determine whether the TaskInfo array is built over time.
String shortSummary()
Return a short description of the total running time.
void start()
Start an unnamed task.
void start(String taskName)
Start a named task.
void stop()
Stop the current task.
String toString()
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

Public Constructors

public StopWatch ()

Also: SpringCore

Construct a new stop watch. Does not start any task.

public StopWatch (String id)

Also: SpringCore

Construct a new stop watch with the given id. Does not start any task.

Parameters
id identifier for this stop watch. Handy when we have output from multiple stop watches and need to distinguish between them.

Public Methods

public StopWatch.TaskInfo getLastTaskInfo ()

Also: SpringCore

Return the last task as a TaskInfo object.

public String getLastTaskName ()

Also: SpringCore

Return the name of the last task.

public long getLastTaskTimeMillis ()

Also: SpringCore

Return the time taken by the last task.

public int getTaskCount ()

Also: SpringCore

Return the number of tasks timed.

public TaskInfo[] getTaskInfo ()

Also: SpringCore

Return an array of the data for tasks performed.

public long getTotalTimeMillis ()

Also: SpringCore

Return the total time in milliseconds for all tasks.

public double getTotalTimeSeconds ()

Also: SpringCore

Return the total time in seconds for all tasks.

public boolean isRunning ()

Also: SpringCore

Return whether the stop watch is currently running.

public String prettyPrint ()

Also: SpringCore

Return a string with a table describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly.

public void setKeepTaskList (boolean keepTaskList)

Also: SpringCore

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".

public String shortSummary ()

Also: SpringCore

Return a short description of the total running time.

public void start ()

Also: SpringCore

Start an unnamed task. The results are undefined if stop() or timing methods are called without invoking this method.

See Also

public void start (String taskName)

Also: SpringCore

Start a named task. The results are undefined if stop() or timing methods are called without invoking this method.

Parameters
taskName the name of the task to start
See Also

public void stop ()

Also: SpringCore

Stop the current task. The results are undefined if timing methods are called without invoking at least one pair start() / stop() methods.

See Also

public String toString ()

Return an informative string describing all tasks performed For custom reporting, call getTaskInfo() and use the task info directly.