Hi friends,
In the code below I removed the sleep() method .. and replaced it with an infinte loop in the run method.. With this Thread object is neither sleeping nor waiting ..
With this the InterruptedException is never thrown ..
And the compiler itself complains if the catch as argument as InterruptedException
The modified code is :
Explanation :In the
Java Documentation of Thread its mentioned that InterruptedException will be invoked only when wait(), wait(long), or wait(long, int), join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods are invoked
For details refer to :
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Thread.html ----------------------------------------------------------------------------
Now taking the actual example as it is ..and calling the t.interrupt() before t.start()
The InterruptedException is never thrown.
I guess the interrupt flag of the Thread object is cleared as t.start() method is called. And hence no InterruptedException thrown.
I am not sure about this.
Regards,
Cody