|
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.PooledSequentialDispatcherAWT
public class PooledSequentialDispatcherAWT
Dispatches Runnable objects sequentially or concurrently on a pool of processor threads. There is one pool per VM.
The static method dispatchConcurrently enqueues the
runnable object for concurrent execution. That is, it will be
processed as soon as one of the pooled threads becomes available.
The instance method dispatch enqueues
the runnable object for sequential execution. It will be processed
by one of the pooled threads when all of the preceedingly enqueued
runnables have been processed. There is one queue per
PooledSequentialDispatcherAWT instance.
Design pattern used: Acceptor Role in design pattern: EventCollector and EventProcessor
Example 1
The following program prints "one", "two", "three" on
concurrent processor threads:
PooledSequentialDispatcherAWT.dispatchConcurrently(
new Runnable(public void run() { System.out.println("one"); });
);
PooledSequentialDispatcherAWT.dispatchConcurrently(
new Runnable(public void run() { System.out.println("two"); });
);
PooledSequentialDispatcherAWT.dispatchConcurrently(
new Runnable(public void run() { System.out.println("three"); });
);
The order of the output is not granted, since the runnables are
executed concurrently. It could be "one","two","three" or "three","one","two"
or any other possible combination. Even intermingled output is possible.
Example 2
The following program prints "one", "two", "three" on
sequential processor threads:
PooledSequentialDispatcherAWT dispatcher = new PooledSequentialDispatcherAWT();
dispatcher.dispatch(
new Runnable(public void run() { System.out.println("one"); });
);
dispatcher.dispatch(
new Runnable(public void run() { System.out.println("two"); });
);
dispatcher.dispatch(
new Runnable(public void run() { System.out.println("three"); });
);
Since all runnables are dispatched by the same PoolDispatcherAWT instance,
it is granted, that they will be executed in the same order as they were
added to the queue. It is also granted, that the output will not be
intermingled, because a runnable will be executed only, when its predecessor
has finished.
| Constructor Summary | |
|---|---|
PooledSequentialDispatcherAWT()
Creates a new PooledSequentialDispatcherAWT and sets the priority of the processor thread to java.lang.Thread.NORM_PRIORITY. |
|
| Method Summary | |
|---|---|
void |
dispatch(java.lang.Runnable runner)
Enqueues the Runnable object, and executes it sequentially on one of the processor threads of the thread pool associated with this class. |
void |
dispatch(java.lang.Runnable runner,
ConcurrentDispatcherAWT pool)
Enqueues the Runnable object, and executes it sequentially on one of the processor threads of the given thread pool or - if there is already a thread associated with the queue - on that thread. |
static void |
dispatchConcurrently(java.lang.Runnable runner)
Enqueues the Runnable object, and executes it concurrently by one of the processor threads. |
void |
join()
|
void |
reassign()
Reassigns the queue to the thread pool provided by this class. |
void |
run()
This method is public as a side effect of the implementation of this class. |
void |
stop()
Stops the event processor and wait until it has finished. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PooledSequentialDispatcherAWT()
| Method Detail |
|---|
public static void dispatchConcurrently(java.lang.Runnable runner)
runner - A runnable.public void dispatch(java.lang.Runnable runner)
dispatch in interface Dispatcherrunner - A runnable.
public void dispatch(java.lang.Runnable runner,
ConcurrentDispatcherAWT pool)
runner - A runnable.public void reassign()
public void stop()
public 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 | ||||||||