Package org.jgroups.util
Class TimeScheduler3
java.lang.Object
org.jgroups.util.TimeScheduler3
- All Implemented Interfaces:
Runnable,TimeScheduler
Implementation of
TimeScheduler. Uses a DelayQueue to order tasks according to execution times- Since:
- 3.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classTasks which runs more than once, either dynamic, fixed-rate or fixed-delay, until cancelledstatic classprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Logprotected booleanprotected ExecutorThread pool used to execute the tasksprotected final BlockingQueue<TimeScheduler3.Task> DelayQueue with tasks being sorted according to execution times (next execution first)protected ThreadThread which removes tasks ready to be executed from the queue and submits them to the pool for executionprotected booleanprotected ThreadPoolprotected ThreadFactory -
Constructor Summary
ConstructorsConstructorDescriptionCreate a scheduler that executes tasks in dynamically adjustable intervalsTimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, int max_queue_size, String rejection_policy) TimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, BlockingQueue<Runnable> queue, String rejection_policy, boolean thread_pool_enabled) TimeScheduler3(ThreadPool thread_pool, ThreadFactory factory, boolean start) -
Method Summary
Modifier and TypeMethodDescriptionprotected TimeScheduler3.Taskadd(TimeScheduler3.Task task) protected <T> TcondGet(Function<ThreadPoolExecutor, T> getter, T default_value) protected voidcondSet(Consumer<ThreadPoolExecutor> setter) protected Future<?> doSchedule(TimeScheduler3.Task task, long initial_delay) Returns a list of tasks currently waiting for execution.voidintReturns the current threads in the pool, or -1 if not applicablelongReturns the keep alive time (in ms) of the thread pool, or -1 if not applicableintReturns the configured max threads, or -1 if not applicableintReturns the configured core threads, or -1 if not applicablebooleanintprotected booleanbooleanReturns true if stop() has been called, false otherwisevoidvoidrun()Future<?> Future<?> scheduleAtFixedRate(Runnable work, long initial_delay, long delay, TimeUnit unit, boolean can_block) protected Future<?> scheduleRecurring(Runnable work, TimeScheduler3.TaskType type, long initial_delay, long delay, TimeUnit unit, boolean can_block) Future<?> scheduleWithDynamicInterval(TimeScheduler.Task work, boolean can_block) Schedule a task for execution at varying intervals.Future<?> scheduleWithFixedDelay(Runnable work, long initial_delay, long delay, TimeUnit unit, boolean can_block) voidsetKeepAliveTime(long time) Sets the keep alive time (in ms) of the thread pool.voidsetMaxThreads(int size) Sets the max pool size.voidsetMinThreads(int size) Sets the core pool size.voidsetNonBlockingTaskHandling(boolean b) voidvoidsetThreadPool(Executor new_pool) intsize()Returns the number of tasks currently in the queue.voidstart()Starts the runner threadvoidstop()Stops the timer, cancelling all tasksprotected voidtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jgroups.util.TimeScheduler
execute, schedule, scheduleAtFixedRate, scheduleWithDynamicInterval, scheduleWithFixedDelay
-
Field Details
-
pool
Thread pool used to execute the tasks -
thread_pool
-
queue
DelayQueue with tasks being sorted according to execution times (next execution first) -
runner
Thread which removes tasks ready to be executed from the queue and submits them to the pool for execution -
log
-
timer_thread_factory
-
non_blocking_task_handling
protected boolean non_blocking_task_handling -
shut_down_pool
protected boolean shut_down_pool
-
-
Constructor Details
-
TimeScheduler3
public TimeScheduler3()Create a scheduler that executes tasks in dynamically adjustable intervals -
TimeScheduler3
public TimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, int max_queue_size, String rejection_policy) -
TimeScheduler3
public TimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, BlockingQueue<Runnable> queue, String rejection_policy, boolean thread_pool_enabled) -
TimeScheduler3
-
-
Method Details
-
setThreadFactory
- Specified by:
setThreadFactoryin interfaceTimeScheduler
-
setThreadPool
-
getMinThreads
public int getMinThreads()Description copied from interface:TimeSchedulerReturns the configured core threads, or -1 if not applicable- Specified by:
getMinThreadsin interfaceTimeScheduler- Returns:
-
setMinThreads
public void setMinThreads(int size) Description copied from interface:TimeSchedulerSets the core pool size. Can be ignored if not applicable- Specified by:
setMinThreadsin interfaceTimeScheduler
-
getMaxThreads
public int getMaxThreads()Description copied from interface:TimeSchedulerReturns the configured max threads, or -1 if not applicable- Specified by:
getMaxThreadsin interfaceTimeScheduler- Returns:
-
setMaxThreads
public void setMaxThreads(int size) Description copied from interface:TimeSchedulerSets the max pool size. Can be ignored if not applicable- Specified by:
setMaxThreadsin interfaceTimeScheduler
-
getKeepAliveTime
public long getKeepAliveTime()Description copied from interface:TimeSchedulerReturns the keep alive time (in ms) of the thread pool, or -1 if not applicable- Specified by:
getKeepAliveTimein interfaceTimeScheduler
-
setKeepAliveTime
public void setKeepAliveTime(long time) Description copied from interface:TimeSchedulerSets the keep alive time (in ms) of the thread pool. Can be ignored if not applicable- Specified by:
setKeepAliveTimein interfaceTimeScheduler
-
getCurrentThreads
public int getCurrentThreads()Description copied from interface:TimeSchedulerReturns the current threads in the pool, or -1 if not applicable- Specified by:
getCurrentThreadsin interfaceTimeScheduler- Returns:
-
getQueueSize
public int getQueueSize() -
size
public int size()Description copied from interface:TimeSchedulerReturns the number of tasks currently in the queue.- Specified by:
sizein interfaceTimeScheduler- Returns:
- The number of tasks currently in the queue.
-
toString
-
isShutdown
public boolean isShutdown()Description copied from interface:TimeSchedulerReturns true if stop() has been called, false otherwise- Specified by:
isShutdownin interfaceTimeScheduler
-
getNonBlockingTaskHandling
public boolean getNonBlockingTaskHandling()- Specified by:
getNonBlockingTaskHandlingin interfaceTimeScheduler
-
setNonBlockingTaskHandling
public void setNonBlockingTaskHandling(boolean b) - Specified by:
setNonBlockingTaskHandlingin interfaceTimeScheduler
-
dumpTimerTasks
Description copied from interface:TimeSchedulerReturns a list of tasks currently waiting for execution. If there are a lot of tasks, the returned string should probably only return the number of tasks rather than a full dump.- Specified by:
dumpTimerTasksin interfaceTimeScheduler- Returns:
-
removeCancelledTasks
public void removeCancelledTasks()- Specified by:
removeCancelledTasksin interfaceTimeScheduler
-
execute
- Specified by:
executein interfaceTimeScheduler
-
schedule
- Specified by:
schedulein interfaceTimeScheduler
-
scheduleWithFixedDelay
public Future<?> scheduleWithFixedDelay(Runnable work, long initial_delay, long delay, TimeUnit unit, boolean can_block) - Specified by:
scheduleWithFixedDelayin interfaceTimeScheduler
-
scheduleAtFixedRate
public Future<?> scheduleAtFixedRate(Runnable work, long initial_delay, long delay, TimeUnit unit, boolean can_block) - Specified by:
scheduleAtFixedRatein interfaceTimeScheduler
-
scheduleWithDynamicInterval
Schedule a task for execution at varying intervals. After execution, the task will get rescheduled afterTimeScheduler.Task.nextInterval()milliseconds. The task is never done until nextInterval() returns a value <= 0 or the task is cancelled.Note that the task is rescheduled relative to the last time is actually executed. This is similar to
TimeScheduler.scheduleWithFixedDelay(Runnable,long,long,java.util.concurrent.TimeUnit).- Specified by:
scheduleWithDynamicIntervalin interfaceTimeScheduler- Parameters:
work- the task to execute
-
start
public void start()Description copied from interface:TimeSchedulerStarts the runner thread- Specified by:
startin interfaceTimeScheduler
-
stop
public void stop()Stops the timer, cancelling all tasks- Specified by:
stopin interfaceTimeScheduler
-
run
public void run() -
scheduleRecurring
protected Future<?> scheduleRecurring(Runnable work, TimeScheduler3.TaskType type, long initial_delay, long delay, TimeUnit unit, boolean can_block) -
doSchedule
-
condSet
-
condGet
-
submitToPool
-
add
-
isRunning
protected boolean isRunning()
-