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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.