O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Completing and linking tasks asynchronously

Java 8 Concurrency API includes a new synchronization mechanism with the CompletableFuture class. This class implements the Future object and the CompletionStage interface that gives it the following two characteristics:

  • As the Future object, a CompletableFuture object will return a result sometime in future
  • As the CompletionStage object, you can execute more asynchronous tasks after the completion of one or more CompletableFuture objects

You can work with a CompletableFuture class in different ways:

  • You can create a CompletableFuture object explicitly and use it as a synchronization point between tasks. One task will establish the value returned by CompletableFuture, using the complete() method, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required