org.apache.commons.lang.time.StopWatch


StopWatch provides a convenient API for timings. The methods do not protect against inappropriate calls. Thus you can call stop before start, resume before suspend, or unsplit before split. The results are indeterminate in these cases.

To start the watch, call start(). At this point you can:

split() the watch to get the time whilst the watch continues in the background. unsplit() will remove the effect of the split. At this point, these three options are available again.

suspend() the watch to pause it. resume() 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() the watch to complete the timing session.

It is intended that the output methods toString() and getTime() should only be called after stop, split or suspend, however a suitable result will be returned at other points.

Constructor Detail

 public StopWatch() 

Method Detail

 public void start() 

Start the stopwatch. This method starts a new timing session, clearing any previous values.

 public void stop() 

Stop the stopwatch. This method ends a new timing session, allowing the time to be retrieved.

 public void reset() 

Reset the stopwatch. This method clears the internal values to allow the object to be reused.

 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() to contine the timing from the original start point.

 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.

 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.

 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.

 public long getTime() 

Get the time on the stopwatch. This is either the time between start and latest split, between start and stop, or the time between the start and the moment this method is called.

Returns: the time in milliseconds

 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.

Returns: the time as a String



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net