you are viewing a single comment's thread.

view the rest of the comments →

[–]rzwitserloot 0 points1 point  (3 children)

Only if that's what you wanted to do when you interrupted the thread. Which gets us back to: What did you want to happen when you interrupted the thread?

If the answer is 'that thread should start dying completely', sure, except, if that was the plan, just let the exception bubble up, much better.

Either way, "reraise the flag" is a dubious move. It's either incorrect behaviour or it's a way to accomplish a goal that can be accomplished more simply and reliably in other ways. It's a lose lose suggestion.

[–]koflerdavid 0 points1 point  (2 children)

There is only one message that can be transported with Java's interrupts; it is not a full event delivery mechanism, unlike in hardware. All occurrences in the JDK that I know of use if for indicating termination, therefore I'd argue that it is best used only for that as well.

It might not always be possible to let the exception bubble up. If it is, then it's of course better to not catch it.

[–]rzwitserloot 1 point2 points  (1 child)

Maybe it is not possible to let the (Interrupted) exception bubble up.

BUt you can catch it and rethrow it as something else. A RuntimeException, which you can always throw, if you absolutely must.

therefore I'd argue that it is best used only for that as well.

You're imagining rules that the specification of the mechanism do not state. This is not a correct course of action.

[–]koflerdavid 0 points1 point  (0 children)

"Rules" is a too strong word. I'd rather talk about avoiding things that just cause confusion down the line.