3 ms·
As another surprising thing, calling interrupted() actually clears the interrupted bit. If it's true, you pretty much have to throw InterruptedException. Oth
by anameaname 8y ago
As another surprising thing, calling interrupted() actually clears the interrupted bit. If it's true, you pretty much have to throw InterruptedException. Otherwise, you have to re set the bit, and exit quietly.
- kevinconaway 8y ago> calling isInterrupted() actually clears the interrupted bit. Thats incorrect. Calling Thread#interrupted[0] clears the interrupt status and returns true if the current thread was interrupted. Thread#isInterrupted()[1] only returns the value of the interrupt status on the thread receiving the method call. The interrupt status is unaffected by that method call. [0] https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#interrupted-- https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.h... [1] https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#isInterrupted-- https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.h...
- anameaname 8y agoYou are right, editted.
- crunchlibrarian 8y agoAs the article itself says, you're unlikely to write correct code if you use these language features. :)