Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.33 :

Posted: Sun Feb 16, 2014 8:35 am
by devlam
"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?

Re: About Question com.enthuware.ets.scjp.v6.2.33 :

Posted: Sun Feb 16, 2014 9:24 am
by admin
1. The statement has now been updated to clearly mention that it is talking about an exception stack trace being printed on the command line.
2. No, sleep() should not be there. That is the point of this option. If you put a call to sleep, then it might generate an InterruptedException as explained by the explanation.
3. Calling interrupt merely set the interrupted flag. But if the thread on which interrupt() is called is blocked on an invocation of wait, join, or sleep methods, then an InterruptedException is raised.

HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.33 :

Posted: Sun Jan 11, 2015 7:43 am
by b1102b1102
delete please

Re: About Question com.enthuware.ets.scjp.v6.2.33 :

Posted: Sun Jan 11, 2015 9:32 am
by admin
I am sorry but I did not understand what you mean. Are you implying that the correct option is not correct?
thank you,
Paul.