Shutdown on Failure and Success
Coordinate task outcomes.
Two Common Patterns
Most concurrent fan-out falls into two shapes:
- All must succeed: if any fails, abandon the rest. Use
ShutdownOnFailure. - First wins: as soon as one succeeds, cancel the rest. Use
ShutdownOnSuccess.
The JDK provides both out of the box.
ShutdownOnFailure Idea
ShutdownOnFailure is for tasks that all need to succeed, such as gathering a user profile and their orders together.
If one subtask throws, the scope cancels the others so you do not waste effort.
All lessons in this course
- The Structured Concurrency Model
- StructuredTaskScope
- Shutdown on Failure and Success
- Error Handling and Cancellation