Consider the following JUnit test:
@Test
public void testSettingInterruptFlag() throws InterruptedException {
Thread blockingThread = new Thread(new Runnable() {
@Override
public synchronized void run() {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
blockingThread.start();
blockingThread.interrupt();
blockingThread.join();
assertTrue(blockingThread.isInterrupted());
}
The test fails even though the interrupted status was set.
I've suspected that the line blockingThread.join();
resets the flag but even when replacing that line with Thread.sleep(3000);
the test still fails. Is this behaviour documented anywhere?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…