June 2018
Intermediate to advanced
408 pages
11h 23m
English
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 ...Read now
Unlock full access