6 · Advanced · lesson 36 of 41
CompletableFuture
Composable async pipelines.
Java
CompletableFuture<String> page = CompletableFuture
.supplyAsync(() -> fetch(url))
.thenApply(String::trim)
.thenCombine(
CompletableFuture.supplyAsync(() -> fetch(url2)),
(a, b) -> a + b)
.exceptionally(err -> "fallback");
String result = page.join();Key takeaways
- ✓thenApply/thenCombine chain non-blocking steps.
- ✓exceptionally / handle recover from failures.