|
Quaqua 5.4.1 2009-07-14 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.randelshofer.quaqua.util.ConcurrentDispatcher
public class ConcurrentDispatcher
Processes Runnable objects concurrently on a pool of processor threads. The order in which the runnable objects are processed is not necesseraly the same in which they were added to the dispatcher. There is one thread pool per instance.
Design pattern used: Acceptor Role in design pattern: EventCollector and EventProcessor
Example
The following program prints "Hello World" on the
processor thread:
// Create the Dispatcher. ConcurrentDispatcher dispatcher = new ConcurrentDispatcher(); // Create the Runnable object. Runnable runner = new Runnable() { public void run() { System.out.println("Hello World"); } }; // Execute the Runnable objekt using the dispatcher. dispatcher.dispatch(runner);
Field Summary | |
---|---|
static int |
ENQUEUE_WHEN_BLOCKED
Set the policy to enqueue the runnable for later execution if there are no available threads in the pool. |
static int |
RUN_WHEN_BLOCKED
Set the policy for blocked execution to be that the current thread executes the command if there are no available threads in the pool. |
Constructor Summary | |
---|---|
ConcurrentDispatcher()
Creates a new ConcurrentDispatcher and sets the priority of the processor thread to java.lang.Thread.NORM_PRIORITY and with up to five concurrent threads in the thread pool. |
|
ConcurrentDispatcher(int priority,
int maxThreadCount)
Creates a new ConcurrentDispatcher. |
Method Summary | |
---|---|
void |
dispatch(java.lang.Runnable runner)
Enqueues the Runnable object, and executes it on a processor thread. |
void |
dispatch(java.lang.Runnable runner,
boolean isLIFO)
Enqueues the Runnable object, and executes it on a processor thread. |
void |
dispose()
Disposes the dispatcher and all associated processes. |
int |
getMaxThreadCount()
Returns the maximal number of concurrent threads. |
protected void |
processEvents()
This method dequeues all Runnable objects from the queue and executes them. |
void |
setMaxThreadCount(int maxThreadCount)
Sets the maximum number of concurrent threads. |
void |
stop()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int ENQUEUE_WHEN_BLOCKED
public static int RUN_WHEN_BLOCKED
Constructor Detail |
---|
public ConcurrentDispatcher()
public ConcurrentDispatcher(int priority, int maxThreadCount)
priority
- The priority of the processor
thread.maxThreadCount
- The maximal number of concurrent
threads in the thread pool.Method Detail |
---|
public void setMaxThreadCount(int maxThreadCount)
maxThreadCount
- Maximal number of concurrent threads.
A value of zero or below zero stops the dispatcher
when the queue is empty.public int getMaxThreadCount()
public void dispatch(java.lang.Runnable runner)
public void dispatch(java.lang.Runnable runner, boolean isLIFO)
public void stop()
protected void processEvents()
public void dispose()
|
Copyright 2003-2007 (c) Werner Randelshofer. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |