thenCombine runs a function over the results of two independent CompletableFutures once both have completed, without either one having to wait for the other to start. The combining function itself only runs after both async computations are done.
CompletableFuture<Integer> a = CompletableFuture.supplyAsync(() -> 6);
CompletableFuture<Integer> b = CompletableFuture.supplyAsync(() -> 7);
CompletableFuture<Integer> combined = a.thenCombine(b, (x, y) -> x * y);
System.out.println("Combined result: " + combined.get());
Combined result: 42
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27