public final class CachedClock extends java.lang.Object implements Clock
Clock
interface that tracks the time in a
private long field that is updated by a background thread once every
millisecond. Timers on most platforms do not have millisecond granularity, so
the returned value may "jump" every 10 or 16 milliseconds. To reduce this
problem, this class also updates the internal time value every 1024 calls to
currentTimeMillis()
.Modifier and Type | Field and Description |
---|---|
private short |
count |
private static CachedClock |
instance |
private static java.lang.Object |
INSTANCE_LOCK |
private long |
millis |
private static int |
UPDATE_THRESHOLD |
Modifier | Constructor and Description |
---|---|
private |
CachedClock() |
Modifier and Type | Method and Description |
---|---|
long |
currentTimeMillis()
Returns the value of a private long field that is updated by a background
thread once every millisecond.
|
static CachedClock |
instance() |
private static final int UPDATE_THRESHOLD
private static volatile CachedClock instance
private static final java.lang.Object INSTANCE_LOCK
private volatile long millis
private short count
public static CachedClock instance()
public long currentTimeMillis()
currentTimeMillis
in interface Clock