[concurrency-interest] Reusing CompletableFuture

Doug Lea dl at cs.oswego.edu
Sun Jul 24 15:41:43 EDT 2016


On 07/24/2016 03:32 PM, Martin Buchholz wrote:

> It may make sense to reuse CompletableFutures where the mutability has been
> removed, e.g. by subclassing.
> Are we safe if we override just obtrudeValue and obtrudeException on a completed
> future?
> Should j.u.c. provide such a thing?

It takes a long enough time to put out major releases that it is easy
to forget that this has been in CompletableFuture for almost a year,
but still not routinely available until jdk9:

     /**
      * Returns a new CompletionStage that is already completed with
      * the given value and supports only those methods in
      * interface {@link CompletionStage}.
      *
      * @param value the value
      * @param <U> the type of the value
      * @return the completed CompletionStage
      * @since 9
      */
     public static <U> CompletionStage<U> completedStage(U value) {
         return new MinimalStage<U>((value == null) ? NIL : value);
     }




More information about the Concurrency-interest mailing list