Package org.cache2k.core.timing
Class TimerWheels
- java.lang.Object
-
- org.cache2k.core.timing.TimerWheels
-
- All Implemented Interfaces:
TimerStructure
public class TimerWheels extends Object implements TimerStructure
Hierarchical timer wheel implementation. The implementation is flexible and can work with variable delta time per time slot and variable slots per wheel level.This implementation is rather simple and has opportunities to improve performance.
- Author:
- Jens Wilke
-
-
Constructor Summary
Constructors Constructor Description TimerWheels(long startTime, long delta, int slots)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelAll()Cancel all taskslongnextRun()Time of next run, or MAX_VALUE if no more tasks are scheduledTimerTaskremoveNextToRun(long time)Return a task that is supposed to execute at the given time or earlier.longschedule(TimerTask task, long time)Insert task.
-
-
-
Method Detail
-
schedule
public long schedule(TimerTask task, long time)
Description copied from interface:TimerStructureInsert task. Scheduling might be not possible if tasks for the requested time have already be run.- Specified by:
schedulein interfaceTimerStructure- Returns:
- 0, if time is already in the past. Or a positive value indicating the execution time of the timer slot
-
cancelAll
public void cancelAll()
Description copied from interface:TimerStructureCancel all tasks- Specified by:
cancelAllin interfaceTimerStructure
-
removeNextToRun
public TimerTask removeNextToRun(long time)
Description copied from interface:TimerStructureReturn a task that is supposed to execute at the given time or earlier. This also moves the clock hand of the timer structure.It may rarely happen that a subsequent method call has an earlier time, in case the operating system schedule delays a thread until the next scheduler event happens.
- Specified by:
removeNextToRunin interfaceTimerStructure- Returns:
- a task or null, if no more tasks are scheduled for the given time
-
nextRun
public long nextRun()
Description copied from interface:TimerStructureTime of next run, or MAX_VALUE if no more tasks are scheduled- Specified by:
nextRunin interfaceTimerStructure
-
-