When I run Test1
no interrupt
exception is shown, but when I run Test2
an interrupt
exception appears.
I really want to know reason behind this.
public class Test1 {
public static void main(final String[] args) throws InterruptedException {
int a = 10;
Thread.currentThread().interrupt();
System.out.println(a);
}
}
When I run the following program, the exception is there, and I am really not sure why, even if it is not waiting (i.e. the queue is empty).
public class Test2 {
public static void main(final String[] args) throws InterruptedException {
BlockingQueue<Integer> q = new LinkedBlockingQueue<Integer>(2);
Thread.currentThread().interrupt();
System.out.println(q.take());
}
}
Please help me understand why java is behaving like this.
Thanks.