"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?
About Question com.enthuware.ets.scjp.v6.2.33 :
Moderator: admin
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.33 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sat Jan 10, 2015 3:37 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.33 :
delete please
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.33 :
I am sorry but I did not understand what you mean. Are you implying that the correct option is not correct?
thank you,
Paul.
thank you,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 220 guests