public class TimeScheduler3 extends Object implements TimeScheduler, Runnable
TimeScheduler
. Uses a DelayQueue
to order tasks according to execution timesModifier and Type | Class and Description |
---|---|
protected class |
TimeScheduler3.RecurringTask
Tasks which runs more than once, either dynamic, fixed-rate or fixed-delay, until cancelled
|
static class |
TimeScheduler3.Task |
protected static class |
TimeScheduler3.TaskType |
Modifier and Type | Field and Description |
---|---|
protected static Log |
log |
protected boolean |
non_blocking_task_handling |
protected Executor |
pool
Thread pool used to execute the tasks
|
protected BlockingQueue<TimeScheduler3.Task> |
queue
DelayQueue with tasks being sorted according to execution times (next execution first)
|
protected Thread |
runner
Thread which removes tasks ready to be executed from the queue and submits them to the pool for execution
|
protected ThreadFactory |
timer_thread_factory |
Constructor and Description |
---|
TimeScheduler3()
Create a scheduler that executes tasks in dynamically adjustable intervals
|
TimeScheduler3(Executor thread_pool,
ThreadFactory factory) |
TimeScheduler3(ThreadFactory factory,
int min_threads,
int max_threads,
long keep_alive_time,
BlockingQueue<Runnable> queue,
String rejection_policy,
boolean thread_pool_enabled) |
TimeScheduler3(ThreadFactory factory,
int min_threads,
int max_threads,
long keep_alive_time,
int max_queue_size,
String rejection_policy) |
Modifier and Type | Method and Description |
---|---|
protected TimeScheduler3.Task |
add(TimeScheduler3.Task task) |
protected <T> T |
condGet(Function<ThreadPoolExecutor,T> getter,
T default_value) |
protected void |
condSet(Consumer<ThreadPoolExecutor> setter) |
protected Future<?> |
doSchedule(TimeScheduler3.Task task,
long initial_delay) |
String |
dumpTimerTasks()
Returns a list of tasks currently waiting for execution.
|
void |
execute(Runnable task,
boolean can_block) |
int |
getCurrentThreads()
Returns the current threads in the pool, or -1 if not applicable
|
long |
getKeepAliveTime()
Returns the keep alive time (in ms) of the thread pool, or -1 if not applicable
|
int |
getMaxThreads()
Returns the configured max threads, or -1 if not applicable
|
int |
getMinThreads()
Returns the configured core threads, or -1 if not applicable
|
boolean |
getNonBlockingTaskHandling() |
int |
getQueueSize() |
protected boolean |
isRunning() |
boolean |
isShutdown()
Returns true if stop() has been called, false otherwise
|
void |
run() |
Future<?> |
schedule(Runnable work,
long initial_delay,
TimeUnit unit,
boolean can_block) |
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) |
void |
setKeepAliveTime(long time)
Sets the keep alive time (in ms) of the thread pool.
|
void |
setMaxThreads(int size)
Sets the max pool size.
|
void |
setMinThreads(int size)
Sets the core pool size.
|
void |
setNonBlockingTaskHandling(boolean b) |
void |
setThreadFactory(ThreadFactory f) |
void |
setThreadPool(Executor new_pool) |
int |
size()
Returns the number of tasks currently in the queue.
|
protected void |
start() |
protected void |
startRunner() |
void |
stop()
Stops the timer, cancelling all tasks
|
protected void |
stopRunner() |
protected void |
submitToPool(TimeScheduler3.Task task) |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
execute, schedule, scheduleAtFixedRate, scheduleWithDynamicInterval, scheduleWithFixedDelay
protected Executor pool
protected final BlockingQueue<TimeScheduler3.Task> queue
protected volatile Thread runner
protected static final Log log
protected ThreadFactory timer_thread_factory
protected boolean non_blocking_task_handling
public TimeScheduler3()
public TimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, int max_queue_size, String rejection_policy)
public TimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, BlockingQueue<Runnable> queue, String rejection_policy, boolean thread_pool_enabled)
public TimeScheduler3(Executor thread_pool, ThreadFactory factory)
public void setThreadFactory(ThreadFactory f)
setThreadFactory
in interface TimeScheduler
public void setThreadPool(Executor new_pool)
public int getMinThreads()
TimeScheduler
getMinThreads
in interface TimeScheduler
public void setMinThreads(int size)
TimeScheduler
setMinThreads
in interface TimeScheduler
public int getMaxThreads()
TimeScheduler
getMaxThreads
in interface TimeScheduler
public void setMaxThreads(int size)
TimeScheduler
setMaxThreads
in interface TimeScheduler
public long getKeepAliveTime()
TimeScheduler
getKeepAliveTime
in interface TimeScheduler
public void setKeepAliveTime(long time)
TimeScheduler
setKeepAliveTime
in interface TimeScheduler
public int getCurrentThreads()
TimeScheduler
getCurrentThreads
in interface TimeScheduler
public int getQueueSize()
public int size()
TimeScheduler
size
in interface TimeScheduler
public boolean isShutdown()
TimeScheduler
isShutdown
in interface TimeScheduler
public boolean getNonBlockingTaskHandling()
getNonBlockingTaskHandling
in interface TimeScheduler
public void setNonBlockingTaskHandling(boolean b)
setNonBlockingTaskHandling
in interface TimeScheduler
public String dumpTimerTasks()
TimeScheduler
dumpTimerTasks
in interface TimeScheduler
public void execute(Runnable task, boolean can_block)
execute
in interface TimeScheduler
public Future<?> schedule(Runnable work, long initial_delay, TimeUnit unit, boolean can_block)
schedule
in interface TimeScheduler
public Future<?> scheduleWithFixedDelay(Runnable work, long initial_delay, long delay, TimeUnit unit, boolean can_block)
scheduleWithFixedDelay
in interface TimeScheduler
public Future<?> scheduleAtFixedRate(Runnable work, long initial_delay, long delay, TimeUnit unit, boolean can_block)
scheduleAtFixedRate
in interface TimeScheduler
public Future<?> scheduleWithDynamicInterval(TimeScheduler.Task work, boolean can_block)
TimeScheduler.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)
.scheduleWithDynamicInterval
in interface TimeScheduler
work
- the task to executeprotected void start()
public void stop()
stop
in interface TimeScheduler
protected Future<?> scheduleRecurring(Runnable work, TimeScheduler3.TaskType type, long initial_delay, long delay, TimeUnit unit, boolean can_block)
protected Future<?> doSchedule(TimeScheduler3.Task task, long initial_delay)
protected void condSet(Consumer<ThreadPoolExecutor> setter)
protected <T> T condGet(Function<ThreadPoolExecutor,T> getter, T default_value)
protected void submitToPool(TimeScheduler3.Task task)
protected TimeScheduler3.Task add(TimeScheduler3.Task task)
protected boolean isRunning()
protected void startRunner()
protected void stopRunner()
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.