Cancellation does not stop code automatically
Future.cancel or interrupt requests cancellation but the task must observe interruption and exit. Blocking code should propagate InterruptedException or restore the interrupt flag.
"Cancellation does not stop code automatically" is a useful thing to know about with java / concurrency. Thanks for sharing it.
Classic
Superb
- @sohmeh▲ 1
Appreciate the write-up on "Cancellation does not stop code automatically". Useful for anyone using java / concurrency.
Valuable
Cancellation is cooperative: the running code must notice the interrupt and exit on its own. Code that catches InterruptedException needs to either propagate it or set the interrupt status again.
Calling Future.cancel or interrupting a thread only sends a signal, and the task has to check for it and return. Blocking calls should rethrow InterruptedException or restore the interrupt flag.
Future.cancel(false)only marks the future cancelled and leaves the task running, whilecancel(true)interrupts it. Other platform gotchas welcome in the comments.Appreciate the write-up on "Cancellation does not stop code automatically". Useful for anyone using java / concurrency.
Specific and to the point: "Cancellation does not stop code automatically". Worth a look if you touch java / concurrency.
Clear note on java / concurrency. "Cancellation does not stop code automatically" is the kind of detail that is easy to overlook.
"Cancellation does not stop code automatically" is a useful thing to know about with java / concurrency. Thanks for sharing it.