Class Watch
java.lang.Object
fc.util.Watch
- Direct Known Subclasses:
NanoWatch
Allows measuring the start and stop time and (hence the elapsed time) of
some event. ("event" meaning something of interest, for example, a method
call). Can be started/stopped repeatedly. (cumulative time across all such
start/stops are available via the
cumulativeTime method).
All times are in milliseconds.
Thread Safety: This class is not threadsafe and it's method do not acquire any locks to reduce any time skew due to lock acquisition. Multiple threads should use separate Watch objects or alternatively, higher level synchronization.
Note: This class used to be called "Timer" but changed to Watch to
avoid an annoying name conflict with java.util.Timer
- Version:
- 1.0, 10/19/2001
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the total time recorded by this Watch (across several starts/stops)longelapsed()This method is an alias fortimeInSeconds()method.longgetTime()This method is an alias fortime()method.doubleUseful in NanoWatch and other subclasses.longThis method is an alias fortimeInSeconds()method.booleanIs the Watch currently running ?static voidvoidreset()Reset all values to zero.voidrestart()Reset all values to zero and restarts the timer.longseconds()This method is an alias fortimeInSeconds()method.start()Start measuring time.voidstop()Stop measuring the timelongtime()Returns the time elapsed since the Watch was started.longUseful for showing the elapsed time in seconds.doubleThis method is an alias forgetTimeInMillis()method.longThis method is an alias fortimeInSeconds()method.toString()Describes the current state of this watch.
-
Constructor Details
-
Watch
-
Watch
public Watch()
-
-
Method Details
-
start
-
stop
Stop measuring the time -
time
Returns the time elapsed since the Watch was started. If the watch was started and stopped, returns the time (in milliseconds) between the start/stop interval.- Throws:
RuntimeException- if the watch was never started before calling this method.
-
getTime
-
timeInSeconds
Useful for showing the elapsed time in seconds. Intervals between, (0 - 499milliseconds are rounded down and500 - 999milliseconds are rounded up). -
getTimeInSeconds
This method is an alias fortimeInSeconds()method. -
seconds
This method is an alias fortimeInSeconds()method. -
elapsed
This method is an alias fortimeInSeconds()method. -
timeSeconds
This method is an alias fortimeInSeconds()method. -
timeMillis
This method is an alias forgetTimeInMillis()method. -
getTimeInMillis
-
cumulativeTime
Returns the total time recorded by this Watch (across several starts/stops) -
reset
Reset all values to zero. This method should be called before this object is used again. Does not restart the timer, call start again when start the timer. -
restart
Reset all values to zero and restarts the timer. -
isRunning
Is the Watch currently running ? -
toString
-
main
-