CompletableFuture is here
summary
CompletableFuture in JDK 8 replaces nested Future+callbacks with chainable operations and shows measurable costs and gains: microbenchmarks with JMH report sequential multiplication ~5 µs, plain Future versions ~12–13 µs, empty CompletableFutures ~8–9 µs, and heavier parallel work that uses thenCombine and thenApply drops overall latency to the hundreds of microseconds (example score ~342 µs). Examples include file I/O wrapped in supplyAsync, flattening with thenCompose, a JAX‑RS/Jersey + Grizzly endpoint that concatenates two CF results, and a ScheduledExecutorService timeout that completes the promise exceptionally.
AI-written summary · about
chapters (33)
- 0:00Introduction and speaker intro
- 0:49Agenda and disclaimers
- 1:32Who writes single-threaded apps?
- 2:16Java concurrency evolution
- 3:45Future limitations
- 5:14Parallelism without main thread
- 6:20Future exception handling
- 7:29Nested futures and errors
- 8:55Problems with nested futures
- 9:41CompletableFuture introduction
- 11:34API and CompletionStage
- 14:05Creating CompletableFuture
- 16:41Synchronous submission methods
- 17:47Simple CompletableFuture examples
- 18:31Transformation methods
- 21:21Mapping and reducing futures
- 23:15Thread execution in methods
- 26:12Working with collections of futures
- 27:17Composing futures
- 30:58Flattening nested futures
- 32:02Blocking and non-blocking access
- 33:26Cost of async operations
- 35:57Performance benchmarks setup
- 38:32Lightweight operation costs
- 39:14Heavy computation parallelism
- 40:20Web demo introduction
- 41:23Server setup and endpoint
- 43:10CompletableFuture in web service
- 45:18Combining futures in service
- 46:43Error handling and timeouts
- 48:51Live demo walkthrough
- 50:20Demo troubleshooting
- 51:04Conclusion and Q&A
