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, ...

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.