O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

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

@Async with CompletableFuture

In the previous section, we saw how we can use java.util.Future to get the result of asynchronous method execution. It provides an isDone() method to check whether the computation is done or not, and a get() method to retrieve the result of the computation when it is done. But there are certain limitations to using the Future API:

  • Suppose we have written code to fetch the latest product price from an e-commerce system through a remote API. This task is time-consuming, so we need to run it asynchronously and use Future to get the result of that task. Now, the problem will occur when the remote API service is down. At that time, we need to complete Future manually by the last cached price of the product and that ...

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