About Question com.enthuware.ets.scjp.v6.2.33 :
Posted: Sun Feb 16, 2014 8:35 am
"It will run and will end without an InterruptedException if //1 is replaced with while(!isInterrupted()) { };"
1. It is Always ending without an InterruppedException because this exception is catched. So main will never throw it.
2. The replacement should be:
while(!isInterrupted()) { Thread.sleep(10000); };
3. I'm not fully understand the isInterrupted(). If with that addition the program will end without an InterruptedException then it looks like the a.interrupt() somehow manages to get the object out of sleep with knowledge that the sleep is inside a isInterrupted() loop and then not throwing the InterruptedException.
How does this work?
1. It is Always ending without an InterruppedException because this exception is catched. So main will never throw it.
2. The replacement should be:
while(!isInterrupted()) { Thread.sleep(10000); };
3. I'm not fully understand the isInterrupted(). If with that addition the program will end without an InterruptedException then it looks like the a.interrupt() somehow manages to get the object out of sleep with knowledge that the sleep is inside a isInterrupted() loop and then not throwing the InterruptedException.
How does this work?