Moving CompletionHandler to java.util.concurrent
Alan Bateman
Alan.Bateman at Sun.COM
Thu Oct 22 02:02:59 PDT 2009
Gili wrote:
> You know what Alan? The more I take a look at
> http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/util/concurrent/ListenableFuture.html
> the more it doesn't make sense to introduce CompletionHandler in Java7.
> Instead of introducing duplicate methods (one that uses Futures, another
> that uses CompletionHandler) we should just have a single method that
> handles both use-cases using a ListenableFuture.
>
> Have you guys reviewed this possibility already...?
>
Yes, this ground has been well covered. If you go back a few years to
AIO4J, you'll see that it had an API that is close to what you are
suggesting now. The API we have now is relatively simple - you wait/poll
for a result using the Future, or you specify a callback (completion
handler) to be invoked when the I/O operation completes. There is no
support for "mixing" of styles where you might be waiting for the result
and also consuming the result in a callback, or where you decide to
register a callback after the fact. If you really need this then you can
wrap the channels and use the completion handlers to drive the framework.
-Alan.
More information about the nio-discuss
mailing list