0Pricing
Java Academy · Lesson

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

  1. The Structured Concurrency Model
  2. StructuredTaskScope
  3. Shutdown on Failure and Success
  4. Error Handling and Cancellation
← Back to Java Academy