[concurrency-interest] CompletableFuture in Java 8

Doug Lea dl at cs.oswego.edu
Wed Dec 3 09:07:17 EST 2014


On 12/01/2014 10:58 AM, √iktor Ҡlang wrote:

> I guess it depends whether one wants that feature overridable (one can go from
> CompletionStage to CompletableFuture with the combinators)

Right. While overriding toCompletableFuture allows CompletionStage
authors to disable direct conversion, it doesn't prevent their
CompletionStage  users from finding less efficient ways of
performing blocking joins in particular. For example:
   CountdownLatch latch = ...;
   CompletableFuture cf = ....thenRun(() -> latch.countDown());
   latch.await();

Which leads me to re-wonder why any CompletionStage implementor
would ever bother to disable.

Digressing: I noticed while googling around for such constructions
that people sometimes use them to ensure that their main()
program using default-ayncs doesn't exit before computation
is complete. It would be better to use
ForkJoinPool.commonPool().awaitQuiescence(timeout, unit).
But this method has timeout arguments that people
probably don't want to think about in this case.
And the need for it is non-obvious to new users.
We should consider doing something about this.


>     But we can/do add new better stuff that we encourage people to use
>     instead of old stuff when it becomes less useful as the world changes.
>
>
> Hmmm, if only there was some kind of successor-like language to Java... :-)

Although any such language that specifically disallowed access to
JDK classes that you don't happen to like might not fare so well :-)

-Doug






More information about the Concurrency-interest mailing list