CompletableFuture: The Promises of Java
summary
CompletableFuture is Java’s equivalent of JavaScript promises: use supplyAsync to run compute in the ForkJoin common pool or pass a custom pool, chain transformations with thenApply, consume with thenAccept and side‑effects with thenRun, recover with exceptionally or handle, and fault with completeExceptionally. Java 9 adds completeOnTimeout/orTimeout so futures don’t live‑lock; examples show 2 → thenApply(x*2) → thenApply(+1) = 5 and a recovery that returns 100 producing 201 when composed. Always pick a timeout strategy.
AI-written summary · about
chapters (25)
- 0:00Introduction
- 1:00What is a Promise
- 2:00Promise Tracks
- 5:00Stages
- 8:00Create Method
- 9:00Print Method
- 10:00Nonblocking
- 13:00Custom pools
- 14:00Methods
- 18:00Keep on going
- 20:00ThenApply
- 24:00Pipeline
- 25:00Unhappy Path
- 29:00Something Went Wrong
- 30:00Runtime Exception
- 32:00Deficiencies
- 34:00Timeout
- 35:00Sleep
- 39:00Time Out
- 40:00Blow Up
- 41:00Combine
- 43:00Reduce
- 44:00Combined
- 45:00One to Many
- 46:00Map vs Flat Map
related talks
52mNew Concurrency Utilities in Java 8
28mBack to the CompletableFuture: Concurrency
55mBack to the CompletableFuture: Concurrency in Action
45mKeynote: Where Promises Fall Short
47mA Deeper Dive into Java Concurrency Updates
48mParallel Streams, CompletableFuture, and All That: Concurrency in Java 8
49mTrading in Futures
56mFlavors of Concurrency in Java
