Cancel signals
- User cancel (UI button)
- Deadline reached (task-level timeout)
- Parent task cancelled (cascading)
- System shutdown (graceful)
Advertisement
Cancellation is cooperative
if (Thread.interrupted()) throw new InterruptedException();
// or
if (ctx.isCancelled()) throw new TaskCancelledException();Tools must check periodically. Tight loops without checks can't be cancelled.
Advertisement
State on cancel
Task moves to CANCELLED. Compensators run for any partial side effects. Never LEAK — data must be consistent.