Package org.jgroups.util
Class Scheduler
- java.lang.Object
-
- org.jgroups.util.Scheduler
-
- All Implemented Interfaces:
java.lang.Runnable
public class Scheduler extends java.lang.Object implements java.lang.Runnable
Implementation of a priority scheduler. The scheduler maintains a queue to the end of which all tasks are added. It continually looks at the first queue element, assigns a thread to it, runs the thread and waits for completion. When a new priority task is added, it will be added to the head of the queue and the scheduler will be interrupted. In this case, the currently handled task is suspended, and the one at the head of the queue handled. This is recursive: a priority task can always be interrupted by another priority task. Recursion ends when no more priority tasks are added, or when the thread pool is exhausted.- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Scheduler.Task
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.Log
log
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.Runnable task)
void
addPrio(java.lang.Runnable task)
boolean
getConcurrentProcessing()
void
run()
void
setConcurrentProcessing(boolean process_concurrently)
void
setListener(SchedulerListener l)
void
start()
void
stop()
Stop the scheduler thread.
-
-
-
Method Detail
-
setListener
public void setListener(SchedulerListener l)
-
getConcurrentProcessing
public boolean getConcurrentProcessing()
-
setConcurrentProcessing
public void setConcurrentProcessing(boolean process_concurrently)
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
addPrio
public void addPrio(java.lang.Runnable task)
-
add
public void add(java.lang.Runnable task)
-
start
public void start()
-
stop
public void stop()
Stop the scheduler thread. The thread may be waiting for its next task (queue.peek()) or it may be waiting on the currently executing thread. In the first case, closing the queue will throw a QueueClosed exception which terminates the scheduler thread. In the second case, after closing the queue, we interrupt the scheduler thread, which then checks whether the queue is closed. If this is the case, the scheduler thread terminates.
-
-