|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread tyrex.services.Clock
Provides an efficient mechanism for obtaining the current
system time. Uses a background thread to automatically increment
an internal clock and periodically synchronize with the system clock.
The method clock
is more efficient than currentTimeMillis
, and also
allows the clock to be artificially advanced for testing purposes.
The clock is thread-safe and consumes a single thread.
Field Summary | |
static int |
SYNCH_EVERY
The number of unsychronized cycles before the clock is synchronized with the system clock. |
static int |
UNSYNCH_TICKS
The number of clock ticks in each unsynchronized cycle. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Method Summary | |
static void |
advance(long byMillis)
Artficially advances the clock. |
static long |
clock()
Returns the current clock. |
static long |
getAdvance()
Returns the number of milliseconds by which the clock is advanced. |
static int |
getUnsynchTicks()
Returns the number of clock ticks in each unsynchronized cycle. |
static void |
main(java.lang.String[] args)
|
void |
run()
|
static void |
setSynchEvery(int every)
Sets the number of unsynchronized cycles before the clock is synchronized with the system clock. |
static void |
setUnsynchTicks(int ticks)
Sets the number of clock ticks in each unsynchronized cycle. |
static long |
synchronize()
|
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int UNSYNCH_TICKS
public static final int SYNCH_EVERY
Method Detail |
public static long clock()
public static void setUnsynchTicks(int ticks)
The internal clock is advanced every cycle, the length of the cycle is controlled by this property. A higher value results in a lower clock resolution.
ticks
- The number of clock ticks (milliseconds) for
each unsynchronized cyclepublic static int getUnsynchTicks()
public static void setSynchEvery(int every)
Synchronization will occur every unsynchTicks * synchEvery milliseconds. The larger the value, the less accurate the clock is.
every
- The number of unsynchronized cyclespublic static void advance(long byMillis)
byMillis
- The number of milliseconds by which to
advance the clock (must be positive)public static long getAdvance()
public void run()
public static long synchronize()
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |