CompletableFuture and its Quirks
summary
CompletableFuture has four practical surprises: cancellation doesn't stop work — cancel() marks the CF but doesn't reliably interrupt the threads actually doing the work; allOf/anyOf treat exceptions like values — allOf returns Void and waits for every completion (no short‑circuit), anyOf can return an exceptional result if it completes first; default async uses the common ForkJoinPool so code can run on unexpected threads (even main) unless an explicit Executor is supplied; applyToEither can prefer an exception over a successful result depending on completion order.
AI-written summary · about
chapters (13)
- 0:00Introduction to futures
- 1:54Synchronous vs asynchronous
- 3:53Java future limitations
- 6:08Handling exceptions
- 8:07Combining futures
- 9:43CompletableFuture basics
- 12:32Cancellation quirks
- 17:31Understanding AllOf method
- 23:54Fixing AllOf method
- 26:49Understanding AnyOf method
- 30:20Thread management
- 36:58ForkJoinPool risks
- 44:03Conclusion and Q&A
