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 tasksvoidcancelAll(TimerTask t)Cancel this timer tasklongnextRun()Time of next run, or -1 if no more tasks are scheduledTimerTaskremoveNextToRun(long time)Return a task that is supposed to execute at the given time or earlier.booleanschedule(TimerTask task, long time)Insert task.
-
-
-
Method Detail
-
schedule
public boolean 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:
- true if scheduled successfully, false if scheduling was not possible because the target time slot would be in the past
-
cancelAll
public void cancelAll(TimerTask t)
Description copied from interface:TimerStructureCancel this timer task- Specified by:
cancelAllin interfaceTimerStructure
-
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 -1 if no more tasks are scheduled- Specified by:
nextRunin interfaceTimerStructure
-
-