I understand perfectly what it does (at least I hope so). It doesn't really interrupt the thread. It makes Thread.isInterrupted()
true, and the code is supposed to check what method and stop the thread itself.
My question is, why do we even need this method? It seems perfectly replaceable by declaring a boolean flag stating whether this thread should be stopped? Doesn't any Java textbook use this boolean flag as the best example of how volatile
keyword should be used?
I am particularly confused, as there seems to be no way to "uninterrupt" the thread, as Thread.resume()
is deprecated. That makes interrupt()
even less useful than a boolean flag I write by myself.
Other than being perhaps a bit easier to write, does Thread.interrupt()
do anything different from my boolean flag?