|
|||||||||
| Home >> All >> org >> apache >> commons >> lang >> [ time overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.lang.time
Class StopWatch

java.lang.Objectorg.apache.commons.lang.time.StopWatch
- public class StopWatch
- extends java.lang.Object
StopWatch provides a convenient API for timings.
To start the watch, call start() 55 . At this point you can:
split()55 the watch to get the time whilst the watch continues in the background.unsplit()55 will remove the effect of the split. At this point, these three options are available again.suspend()55 the watch to pause it.resume()55 allows the watch to continue. Any time between the suspend and resume will not be counted in the total. At this point, these three options are available again.stop()55 the watch to complete the timing session.
It is intended that the output methods toString() 55 and getTime() 55
should only be called after stop, split or suspend, however a suitable result will
be returned at other points.
NOTE: As from v2.1, the methods protect against inappropriate calls. Thus you cannot now call stop before start, resume before suspend or unsplit before split.
1. split(), suspend(), or stop() cannot be invoked twice
2. unsplit() may only be called if the watch has been split()
3. resume() may only be called if the watch has been suspend()
4. start() cannot be called twice without calling reset()
- Since:
- 2.0
- Version:
- $Id: StopWatch.java 189443 2005-06-07 21:28:07Z scolebourne $
| Field Summary | |
private int |
runningState
The current running state of the StopWatch. |
private int |
splitState
Whether the stopwatch has a split time recorded. |
private long |
startTime
The start time. |
private static int |
STATE_RUNNING
|
private static int |
STATE_SPLIT
|
private static int |
STATE_STOPPED
|
private static int |
STATE_SUSPENDED
|
private static int |
STATE_UNSPLIT
|
private static int |
STATE_UNSTARTED
|
private long |
stopTime
The stop time. |
| Constructor Summary | |
StopWatch()
Constructor. |
|
| Method Summary | |
long |
getSplitTime()
Get the split time on the stopwatch. |
long |
getTime()
Get the time on the stopwatch. |
void |
reset()
Resets the stopwatch. |
void |
resume()
Resume the stopwatch after a suspend. |
void |
split()
Split the time. |
void |
start()
Start the stopwatch. |
void |
stop()
Stop the stopwatch. |
void |
suspend()
Suspend the stopwatch for later resumption. |
java.lang.String |
toSplitString()
Gets a summary of the split time that the stopwatch recorded as a string. |
java.lang.String |
toString()
Gets a summary of the time that the stopwatch recorded as a string. |
void |
unsplit()
Remove a split. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
STATE_UNSTARTED
private static final int STATE_UNSTARTED
- See Also:
- Constant Field Values
STATE_RUNNING
private static final int STATE_RUNNING
- See Also:
- Constant Field Values
STATE_STOPPED
private static final int STATE_STOPPED
- See Also:
- Constant Field Values
STATE_SUSPENDED
private static final int STATE_SUSPENDED
- See Also:
- Constant Field Values
STATE_UNSPLIT
private static final int STATE_UNSPLIT
- See Also:
- Constant Field Values
STATE_SPLIT
private static final int STATE_SPLIT
- See Also:
- Constant Field Values
runningState
private int runningState
- The current running state of the StopWatch.
splitState
private int splitState
- Whether the stopwatch has a split time recorded.
startTime
private long startTime
- The start time.
stopTime
private long stopTime
- The stop time.
| Constructor Detail |
StopWatch
public StopWatch()
Constructor.
| Method Detail |
start
public void start()
Start the stopwatch.
This method starts a new timing session, clearing any previous values.
stop
public void stop()
Stop the stopwatch.
This method ends a new timing session, allowing the time to be retrieved.
reset
public void reset()
Resets the stopwatch. Stops it if need be.
This method clears the internal values to allow the object to be reused.
split
public void split()
Split the time.
This method sets the stop time of the watch to allow a time to be extracted. The start time is unaffected, enabling
unsplit()55 to continue the timing from the original start point.
unsplit
public void unsplit()
Remove a split.
This method clears the stop time. The start time is unaffected, enabling timing from the original start point to continue.
suspend
public void suspend()
Suspend the stopwatch for later resumption.
This method suspends the watch until it is resumed. The watch will not include time between the suspend and resume calls in the total time.
resume
public void resume()
Resume the stopwatch after a suspend.
This method resumes the watch after it was suspended. The watch will not include time between the suspend and resume calls in the total time.
getTime
public long getTime()
Get the time on the stopwatch.
This is either the time between the start and the moment this method is called, or the amount of time between start and stop.
getSplitTime
public long getSplitTime()
Get the split time on the stopwatch.
This is the time between start and latest split.
- Since:
- 2.1
toString
public java.lang.String toString()
Gets a summary of the time that the stopwatch recorded as a string.
The format used is ISO8601-like, hours:minutes:seconds.milliseconds.
toSplitString
public java.lang.String toSplitString()
Gets a summary of the split time that the stopwatch recorded as a string.
The format used is ISO8601-like, hours:minutes:seconds.milliseconds.
- Since:
- 2.1
|
|||||||||
| Home >> All >> org >> apache >> commons >> lang >> [ time overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.commons.lang.time.StopWatch