|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jdiagnose.concurrent.ThreadFactoryUser org.jdiagnose.concurrent.QueuedExecutor
An implementation of Executor that queues incoming requests until they can be processed by a single background thread.
The thread is not actually started until the first
execute
request is encountered. Also, if the
thread is stopped for any reason (for example, after hitting
an unrecoverable exception in an executing task), one is started
upon encountering a new request, or if restart()
is
invoked.
Beware that, especially in situations where command objects themselves invoke execute, queuing can sometimes lead to lockups, since commands that might allow other threads to terminate do not run at all when they are in the queue.
[ Introduction to this package. ]
Nested Class Summary | |
protected class |
QueuedExecutor.RunLoop
The runloop is isolated in its own Runnable class just so that the main class need not implement Runnable, which would allow others to directly invoke run, which would never make sense here. |
Nested classes inherited from class org.jdiagnose.concurrent.ThreadFactoryUser |
ThreadFactoryUser.DefaultThreadFactory |
Field Summary | |
protected static java.lang.Runnable |
ENDTASK
Special queue element to signal termination |
protected Channel |
queue_
The queue |
protected QueuedExecutor.RunLoop |
runLoop_
|
protected boolean |
shutdown_
true if thread should shut down after processing current task |
protected java.lang.Thread |
thread_
The thread used to process commands |
Fields inherited from class org.jdiagnose.concurrent.ThreadFactoryUser |
threadFactory_ |
Constructor Summary | |
QueuedExecutor()
Construct a new QueuedExecutor that uses a BoundedLinkedQueue with the current DefaultChannelCapacity as its queue. |
|
QueuedExecutor(Channel queue)
Construct a new QueuedExecutor that uses the supplied Channel as its queue. |
Method Summary | |
protected void |
clearThread()
set thread_ to null to indicate termination |
void |
execute(java.lang.Runnable command)
Arrange for execution of the command in the background thread by adding it to the queue. |
java.lang.Thread |
getThread()
Return the thread being used to process commands, or null if there is no such thread. |
void |
restart()
Start (or restart) the background thread to process commands. |
void |
shutdownAfterProcessingCurrentlyQueuedTasks()
Terminate background thread after it processes all elements currently in queue. |
void |
shutdownAfterProcessingCurrentTask()
Terminate background thread after it processes the current task, removing other queued tasks and leaving them unprocessed. |
void |
shutdownNow()
Terminate background thread even if it is currently processing a task. |
Methods inherited from class org.jdiagnose.concurrent.ThreadFactoryUser |
getThreadFactory, setThreadFactory |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Thread thread_
protected static java.lang.Runnable ENDTASK
protected volatile boolean shutdown_
protected final Channel queue_
protected final QueuedExecutor.RunLoop runLoop_
Constructor Detail |
public QueuedExecutor(Channel queue)
This class does not support any methods that reveal this queue. If you need to access it independently (for example to invoke any special status monitoring operations), you should record a reference to it separately.
public QueuedExecutor()
Method Detail |
public java.lang.Thread getThread()
protected void clearThread()
public void restart()
public void execute(java.lang.Runnable command) throws java.lang.InterruptedException
If the background thread does not exist, it is created and started.
execute
in interface Executor
java.lang.InterruptedException
public void shutdownAfterProcessingCurrentlyQueuedTasks()
public void shutdownAfterProcessingCurrentTask()
public void shutdownNow()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |