|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfc.util.Watch
public class Watch
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
A higher nano-second precision watch.
Constructor Summary | |
---|---|
Watch()
|
|
Watch(java.lang.String name)
|
Method Summary | |
---|---|
long |
cumulativeTime()
Returns the total time recorded by this Watch (across several starts/stops) |
long |
elapsed()
This method is an alias for timeInSeconds() method. |
long |
getTime()
This method is an alias for time() method. |
double |
getTimeInMillis()
Useful in NanoWatch and other subclasses. |
long |
getTimeInSeconds()
This method is an alias for timeInSeconds() method. |
boolean |
isRunning()
Is the Watch currently running ? |
static void |
main(java.lang.String[] args)
|
void |
reset()
Reset all values to zero. |
void |
restart()
Reset all values to zero and restarts the timer. |
long |
seconds()
This method is an alias for timeInSeconds() method. |
Watch |
start()
Start measuring time. |
void |
stop()
Stop measuring the time |
long |
time()
Returns the time elapsed since the Watch was started. |
long |
timeInSeconds()
Useful for showing the elapsed time in seconds. |
double |
timeMillis()
This method is an alias for getTimeInMillis() method. |
long |
timeSeconds()
This method is an alias for timeInSeconds() method. |
java.lang.String |
toString()
Describes the current state of this watch. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Watch(java.lang.String name)
public Watch()
Method Detail |
---|
public Watch start()
Watch w = new Watch().start()
public void stop()
public long time()
java.lang.RuntimeException
- if the watch was never started before calling
this method.public long getTime()
time()
method.
public long timeInSeconds()
0 - 499
milliseconds are rounded down and
500 - 999
milliseconds are rounded up).
public long getTimeInSeconds()
timeInSeconds()
method.
public long seconds()
timeInSeconds()
method.
public long elapsed()
timeInSeconds()
method.
public long timeSeconds()
timeInSeconds()
method.
public double timeMillis()
getTimeInMillis()
method.
public double getTimeInMillis()
getTime()
/time()
functions instead.
This method is defined here so all watches have a common interface and
any instance can be bound to a variable of type Watch
.
public long cumulativeTime()
public void reset()
public void restart()
public boolean isRunning()
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |