why not both Future and CompletionHandler?

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 14 07:54:05 PDT 2011


Sangjin Lee wrote:
> Hi there,
>
> This may have been discussed in the past, but my googling didn't turn 
> up a discussion...
>
> I've been looking at the I/O methods on the AsynchronousSocketChannel, 
> and noticed that they let you interact with *either* Future or 
> CompletionHandler, but not both. Each method flavor seems to have a 
> pair (or more) of overloaded methods that lets you interact with the 
> result only one way. Is there a reason not to use methods that allow 
> you to use both mechanisms (Future and CompletionHandler) instead? For 
> example,
>
> public Future<Void> connect(SocketAddress remote, A attachment, 
> CompletionHandler<Void,? super A> handler);
That's right, you can use a Future or you specify a completion handler 
to consume the result. Do you have examples where you would want to 
consume the result of an I/O operation in a completion handler and at 
the same time wait or poll for the result?

-Alan.


More information about the nio-dev mailing list