public class Watch extends Object
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.
Modifier and Type | Method and Description |
---|---|
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(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. |
String |
toString()
Describes the current state of this watch.
|
public Watch start()
Watch w = new Watch().start()
public void stop()
public long time()
RuntimeException
- if the watch was never started before calling
this 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()
public long cumulativeTime()
public void reset()
public void restart()
public boolean isRunning()
public String toString()