Lesson 29: CompletableFuture & Async Programming
30 Jul 2026 1 min Swarnil Singhai
CompletableFuture chains async operations without blocking threads waiting on each other — the backbone of reactive-style Java code.
Real-time example
A checkout flow fetches inventory and pricing from two microservices in parallel, then combines both results once both finish.
CompletableFuture<Integer> stock = CompletableFuture.supplyAsync(() -> 42);
CompletableFuture<Double> price = CompletableFuture.supplyAsync(() -> 29.99);
stock.thenCombine(price, (s, p) ->
"Stock: " + s + ", Total: " + (s * p))
.thenAccept(System.out::println);
What's happening
thenCombine waits for both futures without blocking the calling thread — both async calls truly run in parallel.
This pattern replaces the old callback-hell approach to combining multiple async results.
Advertisement