Class CachedClock
- java.lang.Object
-
- org.apache.logging.log4j.core.util.CachedClock
-
- All Implemented Interfaces:
Clock
public final class CachedClock extends java.lang.Object implements Clock
Implementation of theClockinterface 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 tocurrentTimeMillis().
-
-
Field Summary
Fields Modifier and Type Field Description private shortcountprivate static CachedClockinstanceprivate static java.lang.ObjectINSTANCE_LOCKprivate longmillisprivate static intUPDATE_THRESHOLD
-
Constructor Summary
Constructors Modifier Constructor Description privateCachedClock()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longcurrentTimeMillis()Returns the value of a private long field that is updated by a background thread once every millisecond.static CachedClockinstance()
-
-
-
Field Detail
-
UPDATE_THRESHOLD
private static final int UPDATE_THRESHOLD
- See Also:
- Constant Field Values
-
instance
private static volatile CachedClock instance
-
INSTANCE_LOCK
private static final java.lang.Object INSTANCE_LOCK
-
millis
private volatile long millis
-
count
private short count
-
-
Method Detail
-
instance
public static CachedClock instance()
-
currentTimeMillis
public long currentTimeMillis()
Returns the value of a private long field that is updated by a background thread once every millisecond. Timers on most platforms do not have millisecond granularity, the returned value may "jump" every 10 or 16 milliseconds. To reduce this problem, this method also updates the internal time value every 1024 calls.- Specified by:
currentTimeMillisin interfaceClock- Returns:
- the cached time
-
-