Skip to content
Advertisement

Tag: interruption

Thread is interrupted by calling interrupt(), but Thread.isInterrupted() returns false

I am testing InterruptedException with the following test code: In run() , I interrupt() current working thread, and caught a InterruptedException. In main thread, my last line of code is a System.out.println(…) which prints out the interrupt status of working thread. Since I have caught InterruptedException in run(), I though I should get the message that workingThread.isInterrupted() is true, but

Interrupting looped threads in Java

I’m trying to understand how threads work in Java and currently investigating how to implement looped threads that can be cancelled. Here’s the code: The thread I create is indended to be interrupted sooner or later. So, I check isInterrupted() flag to decide whether I need to go on and also catch InterruptedException to handle cases when I’m in a

Advertisement