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

supplyAsync() – running a task asynchronously, with a return value

When we want to return a result after finishing a task asynchronously, we can use CompletableFuture.supplyAsync(). It takes Supplier<T> as a parameter and returns CompletableFuture<T>.

Let's check the supplyAsync() method by creating another controller method in our BankController class, with the following example:

@RequestMapping(value = "/synccustbal")  @ResponseBody  public CompletableFuture<String> syncCustomerBalance() {    LOGGER.info("Entering in controller");    CompletableFuture<String> completableFuture =     CompletableFuture.supplyAsync(new Supplier<String>() {            @Override      public String get() {        try {          return syncService.syncCustomerBalance().get(); } catch (InterruptedException ...

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