org.webmacro.util
Class Clock
java.lang.Object
|
+--org.webmacro.util.Clock
- public final class Clock
- extends java.lang.Object
This is an optimization. "System.currentTimeMillis()" is a relatively
slow method, and "new Date()" is an incredibly expensive operation.
This clock performs these operations at regular intervals and makes
the result of the calculations available. You can therefore use this
class to gain rapid access to the current time in situations where
it is good enough to have "close" to the current time.
Field Summary |
static long |
TIME
Every tick interval the following variable is updated with the current system time |
Constructor Summary |
Clock()
|
Method Summary |
static java.util.Date |
getDate()
The current date. |
static void |
main(java.lang.String[] arg)
|
static void |
setTickInterval(int interval)
The clock will tick at least this often. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TIME
public static volatile long TIME
- Every tick interval the following variable is updated with the current system time
Clock
public Clock()
getDate
public static java.util.Date getDate()
- The current date. This object is updated on the tick interval,
but not faster than once per second.
setTickInterval
public static void setTickInterval(int interval)
- The clock will tick at least this often. It may tick more often.
Setting it to zero stops the clock. The actual tick interval used
will be the smallest tick interval ever set. The tickInterval
starts out as 10000 (ten seconds).
main
public static void main(java.lang.String[] arg)