About Question enthuware.ocpjp.v8.2.1324 :

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

Moderator: admin

Post Reply
schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

About Question enthuware.ocpjp.v8.2.1324 :

Post by schchen2000 »

calling interrupt() will cause an InterruptedException ONLY if the thread on which interrupt() is called, is blocked on an invocation of the wait, join, or sleep, methods of this class.
This is simply saying that an InterruptedException will be thrown when a thread, say Thread A, is ALREADY on either wait, join or sleep while an interrupt is being called on THE SAME THREAD, i.e. Thread A.

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

Re: About Question enthuware.ocpjp.v8.2.1324 :

Post by admin »

That is correct.
If you like our products and services, please help us by posting your review here.

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1324 :

Post by schchen2000 »

admin wrote:That is correct.
Thanks. Have a good weekend.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1324 :

Post by __JJ__ »

Hi
It will run and will ALWAYS end with an InterruptedException stack trace on the command line.
This, luckily, is not true, and hence is not marked as a correct answer. But this is not true either:
This is very likely to happen but not with 100% surety. In the exam, watch for statements like this on thread based questions.
The key thing is the words
end with an InterruptedException stack trace
The program doesn't end with an IE stack trace. It's caught. That's the whole point of the exception handler. I understand you might think I'm being pedantic, but I think the language here (everywhere) is important. IE is a subclass of E, IE is thrown, IE is caught, and the program terminates cleanly. If there were not the line

Code: Select all

System.out.println("Ending loop");
then the situation would not be so clear.

Cheers.

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

Re: About Question enthuware.ocpjp.v8.2.1324 :

Post by admin »

There is a call to e.printStackTrace(); in the catch block, so it could potentially print the stack trace on the command line if there is an exception.
A stack trace can be printed by the program code as well! The problem does not end because of the exception but may end with this output on the command line.
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 61 guests