Package org.cache2k.core.timing
Class DefaultTimer
- java.lang.Object
-
- org.cache2k.core.timing.DefaultTimer
-
- All Implemented Interfaces:
NeedsClose,Timer
public class DefaultTimer extends Object implements Timer
Standard timer implementation. Timer tasks are executed via a scheduler that fires at more approximately at second intervals (lag time, configurable). Typically, there is only one scheduler task per timer. In the case that a timer task is scheduled more than one second before the last an earlier scheduler event is inserted. The later scheduler event is not needed any more, but we do not delete scheduler events in this case.- Author:
- Jens Wilke
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SLOTS_PER_WHEELExpecting that expiry values between 0 and 15 minutes are very common, we cover these on the first level.static longDEFAULT_TIMER_LAG_MILLISDefault for timer lag in milliseconds
-
Constructor Summary
Constructors Constructor Description DefaultTimer(org.cache2k.operation.TimeReference clock, org.cache2k.operation.Scheduler scheduler)DefaultTimer(org.cache2k.operation.TimeReference clock, org.cache2k.operation.Scheduler scheduler, long lagTicks)DefaultTimer(org.cache2k.operation.TimeReference c, org.cache2k.operation.Scheduler scheduler, long lagTicks, int steps)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel(TimerTask t)Cancel the timer task.voidcancelAll()Terminates all timer tasks current pending.voidclose(InternalCacheCloseContext closeContext)longgetLagTicks()Lag to gather timer tasks processing.voidschedule(TimerTask task, long time)Schedule the specified timer task for execution at the specified time, in milliseconds.
-
-
-
Field Detail
-
DEFAULT_TIMER_LAG_MILLIS
public static final long DEFAULT_TIMER_LAG_MILLIS
Default for timer lag in milliseconds- See Also:
Cache2kBuilder.timerLag(long, TimeUnit), Constant Field Values
-
DEFAULT_SLOTS_PER_WHEEL
public static final int DEFAULT_SLOTS_PER_WHEEL
Expecting that expiry values between 0 and 15 minutes are very common, we cover these on the first level.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultTimer
public DefaultTimer(org.cache2k.operation.TimeReference clock, org.cache2k.operation.Scheduler scheduler)
-
DefaultTimer
public DefaultTimer(org.cache2k.operation.TimeReference clock, org.cache2k.operation.Scheduler scheduler, long lagTicks)
-
DefaultTimer
public DefaultTimer(org.cache2k.operation.TimeReference c, org.cache2k.operation.Scheduler scheduler, long lagTicks, int steps)
-
-
Method Detail
-
schedule
public void schedule(TimerTask task, long time)
Schedule the specified timer task for execution at the specified time, in milliseconds.- Specified by:
schedulein interfaceTimertime- the time when the task should be run. must be positive or 0. The value 9223372036854775807L is illegal since this would represent eternal timer and does not need to be scheduled.
-
cancel
public void cancel(TimerTask t)
Description copied from interface:TimerCancel the timer task.
-
getLagTicks
public long getLagTicks()
Lag to gather timer tasks processing. In milliseconds.- Specified by:
getLagTicksin interfaceTimer
-
cancelAll
public void cancelAll()
Terminates all timer tasks current pending.
-
close
public void close(InternalCacheCloseContext closeContext)
- Specified by:
closein interfaceNeedsClose
-
-