Page 1 of 1
About Question enthuware.ocpjp.v8.2.1324 :
Posted: Fri May 27, 2016 12:21 pm
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.
Re: About Question enthuware.ocpjp.v8.2.1324 :
Posted: Fri May 27, 2016 12:35 pm
by admin
That is correct.
Re: About Question enthuware.ocpjp.v8.2.1324 :
Posted: Fri May 27, 2016 6:01 pm
by schchen2000
admin wrote:That is correct.
Thanks. Have a good weekend.
Re: About Question enthuware.ocpjp.v8.2.1324 :
Posted: Wed Aug 08, 2018 11:54 am
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.
Re: About Question enthuware.ocpjp.v8.2.1324 :
Posted: Wed Aug 08, 2018 10:13 pm
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.