Name

CompletionService<V>

Synopsis

This interface combines the features of an ExecutorService with the features of a BlockingQueue. A producer thread may submit Callable or Runnable tasks for asynchronous execution. As each submitted task completes, its result, in the form of a Future object, becomes available to be removed from the queue by a consumer thread that calls poll( ) or take( ).

This generic type declares a type variable V, which represents the result type of all tasks on the queue.

public interface CompletionService<V> {
// Public Instance Methods
     Future<V> poll( );  
     Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException;  
     Future<V> submit(Callable<V> task);  
     Future<V> submit(Runnable task, V result);  
     Future<V> take( ) throws InterruptedException;  
}

Implementations

ExecutorCompletionService

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.