Java Concurrency Interview

CompletableFuture and async composition question 92 of 180 junior

What does CompletableFuture add over Future?

Future gives you get() and isDone(), which means the only way to use a result is to block on it or poll for it. Composing two of them means blocking on the first to start the second.

CompletableFuture is a promise you can attach continuations to: thenApply, thenCompose, thenCombine, allOf, exceptionally, handle. Nothing blocks, and the chain runs when the value arrives. It is also completable from the outside, via complete(value) or completeExceptionally(e), which is what makes it the natural bridge from a callback-based client library.

completablefuture basics

Quiz yourself on CompletableFuture and async composition Suggest a correction