Class 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 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:
        schedule in interface Timer
        time - 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: Timer
        Cancel the timer task.
        Specified by:
        cancel in interface Timer
      • getLagTicks

        public long getLagTicks()
        Lag to gather timer tasks processing. In milliseconds.
        Specified by:
        getLagTicks in interface Timer
      • cancelAll

        public void cancelAll()
        Terminates all timer tasks current pending.
        Specified by:
        cancelAll in interface Timer