org.jgroups.util

Class Scheduler

public class Scheduler extends Object implements 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.

Author: Bela Ban

Nested Class Summary
classScheduler.Task
Field Summary
protected static Loglog
Constructor Summary
Scheduler()
Scheduler(int num_threads)
Method Summary
voidadd(Runnable task)
voidaddPrio(Runnable task)
booleangetConcurrentProcessing()
voidrun()
voidsetConcurrentProcessing(boolean process_concurrently)
voidsetListener(SchedulerListener l)
voidstart()
voidstop()
Stop the scheduler thread.

Field Detail

log

protected static final Log log

Constructor Detail

Scheduler

public Scheduler()

Scheduler

public Scheduler(int num_threads)

Method Detail

add

public void add(Runnable task)

addPrio

public void addPrio(Runnable task)

getConcurrentProcessing

public boolean getConcurrentProcessing()

run

public void run()

setConcurrentProcessing

public void setConcurrentProcessing(boolean process_concurrently)

setListener

public void setListener(SchedulerListener l)

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.
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.