tyrex.services
public final class Clock extends Thread
clock
is more efficient than java.lang.System#currentTimeMillis currentTimeMillis
, and also
allows the clock to be artificially advanced for testing purposes.
The clock is thread-safe and consumes a single thread.
Version: $Revision: 1.5 $
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.
|
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(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() |
Parameters: byMillis The number of milliseconds by which to advance the clock (must be positive)
Returns: The current clock
Returns: The number of milliseconds by which the clock is advanced
Returns: The number of clock ticks (milliseconds) for each unsynchronized cycle
Synchronization will occur every unsynchTicks * synchEvery milliseconds. The larger the value, the less accurate the clock is.
Parameters: every The number of unsynchronized cycles
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.
Parameters: ticks The number of clock ticks (milliseconds) for each unsynchronized cycle