Closed
Description
JVM tends to ignore interrupt signal received by a thread when debugger is attached.
See the following test case
public class ThreadTest {
public static void main(String[] args) throws InterruptedException {
long start=System.currentTimeMillis();
Thread.currentThread().interrupt();
try {
Thread.sleep(20000L);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Time: " + (System.currentTimeMillis() - start) + " ms");
}
}
Test 1(Without JDB attached):
$ java ThreadTest
Interruptting
> Thread enterring sleep for 3 Seconds
Exception in thread "main" java.lang.InterruptedException
at java.lang.Thread.sleep(Native Method)
at java.lang.Thread.sleep(Thread.java:909)
at ThreadTest.main(ThreadTest.java:8)
Test 2(With JDB attached):
$ java -agentlib:jdwp=transport=dt_socket,server=y,address=12345 ThreadTest
Listening for transport dt_socket at address: 12345
Interruptting
> Thread enterring sleep for 3 Seconds
< Thread Sleeping end
Time: 9789 ms
Test 2 didn't throw InterruptedException when JDB is attached and stepped through code.