About Question enthuware.ocpjp.v8.2.1549 :

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.1549 :

Post by schchen2000 »

In this question, we've got 2 threads. One thread launched by calling a.start() and the other thread being main thread.

When you say
Thread.sleep(1000);
which thread are you trying to put to sleep? I think it's the main thread that would go to sleep. Is that correct?

In this question, the InterruptedException WON'T be thrown because the thread launched by a.start() was never on wait(), join() or sleep() when a.interrupt() was called. Do I understand this correctly?

Many thanks.

Schmichael
Last edited by schchen2000 on Wed May 11, 2016 10:00 pm, edited 1 time in total.

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

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

Post by admin »

1. Correct. The thread that calls sleep is the one that goes to sleep.
2. 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.1549 :

Post by schchen2000 »

Thank you.

Schmichael

Harvey Manfrenjensen
Posts: 14
Joined: Fri May 11, 2018 6:59 am
Contact:

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

Post by Harvey Manfrenjensen »

By the way, if System.out.println("Ending loop"); is commented out,
the code still can not be compiled because of empty statement behind the while loop.
Phhhuuu... :-)

Regards, Paul

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

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

Post by __JJ__ »

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.
Hi
The above surely cannot be true, for otherwise there would not be hundreds of methods that declare they throw InterruptedException. I apologize if I'm missing something, but you have capitalized the word only, and I cannot see that the statement is correct. There are thread states of BLOCKED and WAITING; any thread in WAITING I would've thought would throw an IE when interrupted (but I don't know about blocked).

Thanks.

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

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

Post by admin »

Calling other methods may also throw an IE but this is talking about the case when calling interrupt on a thread will throw an InterruptedException.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 36 guests