I have this bit of code:
public void run()
{
System.out.println("ciao");
try{
throw new InterruptedException();
}catch(InterruptedException ie){ //catch will clear the interrupted status
Thread.currentThread().interrupt();}//it will set back the interrupted status
However by following this pattern if I call the following method:
Thread1 t1 = new Thread1();//obviously Thread1 extends Thread
t1.start();
System.out.println(t1.isInterrupted());
The result is "false";
On the other hand if I remove the throw new InterruptedException();
and I try to interrupt it from the main method it gives back the result I expected:
Thread1 t1 = new Thread1();
t1.start();
t1.interrupt();
System.out.println(t1.isInterrupted());
It will return "true".
It's just a mere consistency memory problem or I am doing something wrong in the code? Thanks in advance.
EDIT: I edited the question removing the method join() as indicated by JB Nizet still the problem persists.