Muhammed Senussi
Muhammed Senussi
  • Muhammed Senussi
Structured Concurrency Makes Cancellation Legible
Java

Concurrent code written with executors tends to leak two things: threads and intent. Structured concurrency addresses the second, and the first follows.

Scope as a lifetime

Forking inside a scope means the tasks cannot outlive it. If one fails, the others are cancelled; if the caller is interrupted, everything below is too. The shape of the code finally matches the shape of the work.

  • A timeout on the scope applies to the whole fan-out, not to each call separately.
  • Stack traces regain their meaning, because the parent is genuinely the parent.
  • Partial results become an explicit decision rather than an accident of ordering.

It is one of those APIs that reads as obvious in hindsight, which is usually the sign of a good one.

2 Comments

  • Sanne de Vries

    April 8, 2025

    Heb je het al in productie draaien of nog als preview?

    • Muhammed Senussi

      Muhammed Senussi

      AuthorApril 8, 2025

      In productie op één service, en alleen op een pad waar we een fallback hebben. Ik zou er nog geen betaalstroom op bouwen, maar de API is de eerste die ik niet wil weggooien.

Leave a comment