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

CompletableFuture with Spring Async

The CompletableFuture class was introduced in Java 8, and it provides a simple way to write asynchronous, multithreaded, non-blocking code. With Spring MVC, it is also possible to use CompletableFuture with controllers, services, and repositories from public methods annotated with @AsyncCompletableFuture implements the Future interface, which provides the result of an asynchronous computation.

We can create CompletableFuture in the following simple way:

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

To get the result of this CompletableFuture, we can call the CompletableFuture.get() method. This method will be blocked until Future is completed. For that, we can manually ...

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