There's more...

In the example of this recipe, we used the complete(), get(), join(), supplyAsync(), thenApplyAsync(), thenAcceptAsync(), and allOf() methods of the CompletableFuture class. However, this class has a lot of useful methods that help increase the power and flexibility of this class. These are the most interesting ones:

  • Methods to complete a CompletableFuture object: In addition to the complete() method, the CompletableFuture class provides the following three methods:
    • cancel(): This completes CompletableFuture with a CancellationException exception.
    • completeAsync(): This completes CompletableFuture with the result of the Supplier object passed as a parameter. The Supplier object is executed in a different thread by the default ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.