|
CubeTwister 2.0alpha142 2012-02-11 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectch.randelshofer.util.ConcurrentDispatcherAWT
public class ConcurrentDispatcherAWT
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 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.
ConcurrentDispatcherAWT dispatcher = new ConcurrentDispatcherAWT();
// 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 | |
|---|---|
ConcurrentDispatcherAWT()
Creates a new ConcurrentDispatcherAWT 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. |
|
ConcurrentDispatcherAWT(int priority,
int threadMax)
Creates a new ConcurrentDispatcherAWT. |
|
| Method Summary | |
|---|---|
void |
dispatch(java.lang.Runnable runner)
Enqueues the Runnable object, and executes it on a processor thread. |
void |
join()
|
void |
run()
This method is public as a side effect of the way how this class is implemented. |
void |
setMaxThreads(int threadMax)
Sets the maximum number of concurrent threads. |
| 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 ConcurrentDispatcherAWT()
public ConcurrentDispatcherAWT(int priority,
int threadMax)
priority - The priority of the processor
thread.threadMax - The maximal number of concurrent
threads in the thread pool.| Method Detail |
|---|
public void setMaxThreads(int threadMax)
threadMax - Maximal number of concurrent threads.
A value of zero or below zero stops the dispatcher
when the queue is empty.public void dispatch(java.lang.Runnable runner)
dispatch in interface Dispatcherpublic void run()
This method dequeues all Runnable objects from the queue and executes them. The method returns when the queue is empty.
run in interface java.lang.Runnable
public void join()
throws java.lang.InterruptedException
join in interface Dispatcherjava.lang.InterruptedException
|
(c) Werner Randelshofer. All rights reserved. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||