Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.jgroups.util
Class Scheduler  view Scheduler download Scheduler.java

java.lang.Object
  extended byorg.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. Resursion ends when no more priority tasks are added, or when the thread pool is exhausted.


Nested Class Summary
 class Scheduler.Task
           
 
Field Summary
(package private)  boolean concurrent_processing
          Process items on the queue concurrently.
(package private)  Scheduler.Task current_task
           
(package private)  SchedulerListener listener
           
protected static org.apache.commons.logging.Log log
           
(package private)  int NUM_THREADS
          max number of threads, will only be allocated when needed
(package private)  ThreadPool pool
           
(package private)  Queue queue
           
(package private)  java.lang.Thread sched_thread
           
(package private) static int THREAD_JOIN_TIMEOUT
           
(package private) static int WAIT_FOR_THREAD_AVAILABILITY
           
 
Constructor Summary
Scheduler()
           
Scheduler(int num_threads)
           
 
Method Summary
 void add(java.lang.Runnable task)
           
 void addPrio(java.lang.Runnable task)
           
 boolean getConcurrentProcessing()
           
 void run()
          This method will be called by whoever wishes to run your class implementing Runnable.
 void setConcurrentProcessing(boolean process_concurrently)
           
 void setListener(SchedulerListener l)
           
 void start()
           
 void stop()
          Stop the scheduler thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

final Queue queue

sched_thread

java.lang.Thread sched_thread

current_task

Scheduler.Task current_task

pool

ThreadPool pool

listener

SchedulerListener listener

log

protected static final org.apache.commons.logging.Log log

concurrent_processing

boolean concurrent_processing
Process items on the queue concurrently. The default is to wait until the processing of an item has completed before fetching the next item from the queue. Note that setting this to true may destroy the properties of a protocol stack, e.g total or causal order may not be guaranteed. Set this to true only if you know what you're doing !


NUM_THREADS

int NUM_THREADS
max number of threads, will only be allocated when needed


WAIT_FOR_THREAD_AVAILABILITY

static final int WAIT_FOR_THREAD_AVAILABILITY
See Also:
Constant Field Values

THREAD_JOIN_TIMEOUT

static final int THREAD_JOIN_TIMEOUT
See Also:
Constant Field Values
Constructor Detail

Scheduler

public Scheduler()

Scheduler

public Scheduler(int num_threads)
Method Detail

setListener

public void setListener(SchedulerListener l)

getConcurrentProcessing

public boolean getConcurrentProcessing()

setConcurrentProcessing

public void setConcurrentProcessing(boolean process_concurrently)

run

public void run()
Description copied from interface: java.lang.Runnable
This method will be called by whoever wishes to run your class implementing Runnable. Note that there are no restrictions on what you are allowed to do in the run method, except that you cannot throw a checked exception.

Specified by:
run in interface java.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.