[concurrency-interest] CompletableFuture

Doug Lea dl at cs.oswego.edu
Thu Dec 27 13:34:54 EST 2012


An initial version of JDK8 java.util.concurrent.CompletableFuture
is now available. See javadocs at:
http://gee.cs.oswego.edu/dl/jsr166/dist/docs/java/util/concurrent/CompletableFuture.html
and source at
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/CompletableFuture.java?view=log

This class implements functionality that has variously been
discussed under names SettableFuture, FutureValue, Promise, and
probably others.

Because of heavy use of function-types, this version is only
compilable/usable using recent JDK8-lambda builds (I think
including the current one at http://jdk8.java.net/lambda).
It would be possible to create a jsr166e version that defined
nested interface types to be usable stand-alone under JDK7,
but it would be at best unpleasant to use without lambda support.

The basic design is a semi-fluent API in which you can arrange:
  (sequential or async)
  (functions or actions)
triggered on completion of
   one ("then") or two ("andThen" and "orThen")
others. As in:
   CompletableFuture<String> f = ...; g = ...
   f.then((s -> aStringFunction(s)).thenAsync(s -> ...);
or
   f.andThen(g, (s, t) -> combineStrings).or(CompletableFuture.async(()->...)....

Comments and suggestions (as always, especially, experience-driven
ones) would be welcome.

-Doug







More information about the Concurrency-interest mailing list