|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.util.TimeScheduler3
public class TimeScheduler3
Implementation of TimeScheduler
. Based on the TimeScheduler2
implementation
with various fixes and enhancements. Uses a DelayQueue
to order tasks according to execution times
Nested Class Summary | |
---|---|
protected class |
TimeScheduler3.RecurringTask
Tasks which runs more than once, either dynamic, fixed-rate or fixed-delay, until cancelled |
protected static class |
TimeScheduler3.Task
|
protected static class |
TimeScheduler3.TaskType
|
Field Summary | |
---|---|
protected static Log |
log
|
protected java.util.concurrent.ThreadPoolExecutor |
pool
Thread pool used to execute the tasks |
protected java.util.concurrent.BlockingQueue<TimeScheduler3.Task> |
queue
DelayQueue with tasks being sorted according to execution times (next execution first) |
protected java.lang.Thread |
runner
Thread which removes tasks ready to be executed from the queue and submits them to the pool for execution |
protected boolean |
running
|
protected ThreadFactory |
timer_thread_factory
|
Constructor Summary | |
---|---|
TimeScheduler3()
Create a scheduler that executes tasks in dynamically adjustable intervals |
|
TimeScheduler3(ThreadFactory factory,
int min_threads,
int max_threads,
long keep_alive_time,
int max_queue_size,
java.lang.String rejection_policy)
|
Method Summary | |
---|---|
protected TimeScheduler3.Task |
add(TimeScheduler3.Task task)
|
protected java.util.concurrent.Future<?> |
doSchedule(TimeScheduler3.Task task,
long initial_delay)
|
java.lang.String |
dumpTimerTasks()
Returns a list of tasks currently waiting for execution. |
void |
execute(java.lang.Runnable task)
Executes command with zero required delay. |
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 |
int |
getQueueSize()
|
boolean |
isShutdown()
Returns true if stop() has been called, false otherwise |
void |
run()
|
java.util.concurrent.Future<?> |
schedule(java.lang.Runnable work,
long initial_delay,
java.util.concurrent.TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay. |
java.util.concurrent.Future<?> |
scheduleAtFixedRate(java.lang.Runnable work,
long initial_delay,
long delay,
java.util.concurrent.TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. |
protected java.util.concurrent.Future<?> |
scheduleRecurring(java.lang.Runnable work,
TimeScheduler3.TaskType type,
long initial_delay,
long delay,
java.util.concurrent.TimeUnit unit)
|
java.util.concurrent.Future<?> |
scheduleWithDynamicInterval(TimeScheduler.Task work)
Schedule a task for execution at varying intervals. |
java.util.concurrent.Future<?> |
scheduleWithFixedDelay(java.lang.Runnable work,
long initial_delay,
long delay,
java.util.concurrent.TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. |
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 |
setThreadFactory(ThreadFactory f)
|
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 entry)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final java.util.concurrent.ThreadPoolExecutor pool
protected final java.util.concurrent.BlockingQueue<TimeScheduler3.Task> queue
protected java.lang.Thread runner
protected volatile boolean running
protected static final Log log
protected ThreadFactory timer_thread_factory
Constructor Detail |
---|
public TimeScheduler3()
public TimeScheduler3(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, int max_queue_size, java.lang.String rejection_policy)
Method Detail |
---|
public void setThreadFactory(ThreadFactory f)
setThreadFactory
in interface TimeScheduler
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 java.lang.String toString()
toString
in class java.lang.Object
public boolean isShutdown()
TimeScheduler
isShutdown
in interface TimeScheduler
public java.lang.String dumpTimerTasks()
TimeScheduler
dumpTimerTasks
in interface TimeScheduler
public void execute(java.lang.Runnable task)
TimeScheduler
execute
in interface TimeScheduler
task
- the task to executepublic java.util.concurrent.Future<?> schedule(java.lang.Runnable work, long initial_delay, java.util.concurrent.TimeUnit unit)
TimeScheduler
schedule
in interface TimeScheduler
work
- the task to executeinitial_delay
- the time from now to delay executionunit
- the time unit of the delay parameter
public java.util.concurrent.Future<?> scheduleWithFixedDelay(java.lang.Runnable work, long initial_delay, long delay, java.util.concurrent.TimeUnit unit)
TimeScheduler
scheduleWithFixedDelay
in interface TimeScheduler
work
- the task to executeinitial_delay
- the time to delay first executiondelay
- the delay between the termination of one execution and the commencement of the nextunit
- the time unit of the initialDelay and delay parameters
public java.util.concurrent.Future<?> scheduleAtFixedRate(java.lang.Runnable work, long initial_delay, long delay, java.util.concurrent.TimeUnit unit)
TimeScheduler
scheduleAtFixedRate
in interface TimeScheduler
work
- the task to executeinitial_delay
- the time to delay first executiondelay
- the period between successive executionsunit
- the time unit of the initialDelay and period parameters
public java.util.concurrent.Future<?> scheduleWithDynamicInterval(TimeScheduler.Task work)
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
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
public void run()
run
in interface java.lang.Runnable
protected java.util.concurrent.Future<?> scheduleRecurring(java.lang.Runnable work, TimeScheduler3.TaskType type, long initial_delay, long delay, java.util.concurrent.TimeUnit unit)
protected java.util.concurrent.Future<?> doSchedule(TimeScheduler3.Task task, long initial_delay)
protected void submitToPool(TimeScheduler3.Task entry)
protected TimeScheduler3.Task add(TimeScheduler3.Task task)
protected void startRunner()
protected void stopRunner()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |