Async Method Calls using CompletableFuture in Spring Boot

In my previous post, I discussed on CompletableFuture provided by Java concurrency API in JDK 8 onwards. In this article, I want to discuss on using CompletableFuture in a Spring Boot application. 🎯 ThreadPoolTaskExecutor in Spring Boot Spring offers ThreadPoolTaskExecutor as a Java bean which is an abstraction of ThreadPoolExecutor of Java concurrency API. It has key configuration values which you can configure for your application. corePoolSize: It is the minimum number of workers which Spring will keep alive without getting timed out....

Last Updated April 8, 2022 · 3 min · 593 words · Anshul Gautam

Reactive Programming using CompletableFuture in Java

Java 8 introduced CompletableFuture as part of it’s concurrency API. This is very helpful when we want to nest operations around asynchronous computations, using the native Java API only. Prior to introducing CompletableFuture, we had Future which provided asynchronous callbacks. But there were few problems associated with Future. CompletableFuture addresses them well. Let’s start with understanding what were the issues with Future, that paved the way for CompletableFuture. 🎯 Drawbacks with Future We cannot manually complete the Future object Lack of proper Exception Handling options available We cannot chain multiple Future objects together In the below example, I am creating a simple Future, and trying to get the result from it....

Last Updated April 7, 2022 · 5 min · 942 words · Anshul Gautam