Class ExecutionCompletionService<V>
- All Implemented Interfaces:
CompletionService<V>
CompletionService that uses a supplied ExecutionService
to execute tasks. This class arranges that submitted tasks are,
upon completion, placed on a queue accessible using take.
The class is lightweight enough to be suitable for transient use
when processing groups of tasks.
This class must be used instead of a ExecutorCompletionService
provided from java.util.concurrent package. The
ExecutorCompletionService may not be used since it requires the use
of a non serializable RunnableFuture object. Since a ExecutionService
may only be used with serializable request objects, this class must be used
instead.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BlockingQueue<NotifyingFuture<V>> protected final ExecutionServiceprotected final ExecutionCompletionService<V>.QueueingListener -
Constructor Summary
ConstructorsModifierConstructorDescriptionExecutionCompletionService(ExecutionService executor) Creates an ExecutorCompletionService using the supplied executor for base task execution and aLinkedBlockingQueueas a completion queue.ExecutionCompletionService(ExecutionService executor, BlockingQueue<NotifyingFuture<V>> completionQueue) Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue.protectedExecutionCompletionService(ExecutionService executor, BlockingQueue<NotifyingFuture<V>> completionQueue, ExecutionCompletionService<V>.QueueingListener listener) This constructor is here if someone wants to override this class and provide their own QueueingListener to possibly listen in on futures being finished -
Method Summary
Modifier and TypeMethodDescriptionpoll()invalid @inheritDoc
{@inheritDoc CompletionService}invalid @inheritDoc
{@inheritDoc CompletionService}invalid @inheritDoc
{@inheritDoc CompletionService}invalid @inheritDoc
{@inheritDoc CompletionService}take()invalid @inheritDoc
{@inheritDoc CompletionService}
-
Field Details
-
executor
-
completionQueue
-
listener
-
-
Constructor Details
-
ExecutionCompletionService
Creates an ExecutorCompletionService using the supplied executor for base task execution and aLinkedBlockingQueueas a completion queue.- Parameters:
executor- the executor to use- Throws:
NullPointerException- if executor is null
-
ExecutionCompletionService
public ExecutionCompletionService(ExecutionService executor, BlockingQueue<NotifyingFuture<V>> completionQueue) Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue.- Parameters:
executor- the executor to usecompletionQueue- the queue to use as the completion queue normally one dedicated for use by this service- Throws:
NullPointerException- if executor is null
-
ExecutionCompletionService
protected ExecutionCompletionService(ExecutionService executor, BlockingQueue<NotifyingFuture<V>> completionQueue, ExecutionCompletionService<V>.QueueingListener listener) This constructor is here if someone wants to override this class and provide their own QueueingListener to possibly listen in on futures being finished- Parameters:
executor- the executor to usecompletionQueue- the queue to use as the completion queue normally one dedicated for use by this servicelistener- the listener to notify. To work properly this listner should at minimum call the super.futureDone or else this completion service may not work correctly.- Throws:
NullPointerException- if executor is null
-
-
Method Details
-
submit
invalid @inheritDoc
{@inheritDoc CompletionService}This future object may not be used as a NotifyingFuture. That is because internally this class sets the listener to provide ability to add to the queue.
- Specified by:
submitin interfaceCompletionService<V>
-
submit
invalid @inheritDoc
{@inheritDoc CompletionService}This future object may not be used as a NotifyingFuture. That is because internally this class sets the listener to provide ability to add to the queue.
- Specified by:
submitin interfaceCompletionService<V>
-
take
invalid @inheritDoc
{@inheritDoc CompletionService}This future may safely be used as a NotifyingFuture if desired. This is because if it tries to set a listener it will be called immediately since the task has already been completed.
- Specified by:
takein interfaceCompletionService<V>- Throws:
InterruptedException
-
poll
invalid @inheritDoc
{@inheritDoc CompletionService}This future may safely be used as a NotifyingFuture if desired. This is because if it tries to set a listener it will be called immediately since the task has already been completed.
- Specified by:
pollin interfaceCompletionService<V>
-
poll
invalid @inheritDoc
{@inheritDoc CompletionService}This future may safely be used as a NotifyingFuture if desired. This is because if it tries to set a listener it will be called immediately since the task has already been completed.
- Specified by:
pollin interfaceCompletionService<V>- Throws:
InterruptedException
-