This class implements the
CompletionService interface, which uses an
Executor object passed to its constructor for
executing the tasks passed to its submit( )
method. As these tasks complete, their result (or exception) is
placed, in the form of a Future object, on an
internal queue and becomes available for removal with the blocking
take( ) method or the nonblocking or timed
poll( ) methods.
This class is useful when you want to execute a number of tasks
concurrently and want to process their results in whatever order they
complete. See Executors for a source of
Executor objects to use with this class.
Figure 16-83. java.util.concurrent.ExecutorCompletionService<V>
public class
ExecutorCompletionService<V> implements CompletionService<V> {
// Public Constructors
public
ExecutorCompletionService (Executor
executor );
public
ExecutorCompletionService (Executor
executor , BlockingQueue<Future<V>>
completionQueue );
// Methods Implementing CompletionService
public Future<V>
poll ( );
public Future<V>
poll (long
timeout , TimeUnit
unit ) throws InterruptedException;
public Future<V>
submit (Callable<V>
task );
public Future<V>
submit (Runnable
task , V
result );
public Future<V>
take ( ) throws InterruptedException;
}