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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

b1102b1102
Posts: 1
Joined: Sat Jan 10, 2015 3:37 pm
Contact:

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

Post by b1102b1102 »

delete please

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 220 guests