216. CompletableFuture

JDK 8 has made a significant step forward in the world of asynchronous programming by enhancing Future with CompletableFuture. The main limitations of Future are:

  • It cannot be explicitly complete.
  • It doesn't support callbacks for performing actions on the result.
  • They cannot be chained or combined for obtaining complex asynchronous pipelines.
  • It doesn't provide exception handling.

A CompletableFuture doesn't have these limitations. A simple, but useless CompletableFuture can be written as follows:

CompletableFuture<Integer> completableFuture 
= new CompletableFuture<>();

The result can be obtained via the blocking get() method:

completableFuture.get();

In addition to this, let's see several examples of running asynchronous tasks in the context of an e-commerce platform. We add these examples in a helper class named CustomerAsyncs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.56.29