CompletableFuture

A Future that can be completed later and chained, letting you describe asynchronous steps such as transform, combine and recover without nesting callbacks.

In more detail

Methods such as thenApply and thenCombine return new futures, so each step is an immutable description of work that runs when its input is ready. A failure skips the later success steps until exceptionally or a final handler deals with it. join and get still block, so call them only at a boundary where waiting is safe. Choose an executor explicitly for blocking work instead of the common pool.

Example

CompletableFuture.supplyAsync(() -> "ready").thenApply(String::toUpperCase).join()

Related terms

Taught in

References