About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

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

Moderator: admin

Post Reply
sjsidjain
Posts: 1
Joined: Thu Mar 03, 2016 8:46 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by sjsidjain »

why option 1 of this question will create deadlock??

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

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

Post by admin »

Because if you do that two thread will try to acquire the same locks in a different order. You may want to read this for more details: http://tutorials.jenkov.com/java-concur ... ntion.html

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

steinov
Posts: 19
Joined: Wed Feb 08, 2023 3:11 am
Contact:

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

Post by steinov »

Isn't option 3 also correct? Even though it is overkill, it does avoid a deadlock. Or is it because of the "must"? If that's the case, the phrasing is a bit misleading in my opinion. Is this kind of phrasing something I can expect on the exam?

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

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

Post by admin »

How will the code ensure that second thread calls getLocks only after the first thread is exits out of it?
If you like our products and services, please help us by posting your review here.

steinov
Posts: 19
Joined: Wed Feb 08, 2023 3:11 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by steinov »

I agree with you that you can't ensure that the getLocks() method is not called before the first thread exits out of it without a locking mechanism or the like. But that doesn't change the fact that it will avoid a deadlock if the second thread would call the getLocks() method after the first thread exits out of it. Even though in practice it would result in some really ugly code, if at all possible. But it wasn't asking about the viability of the option.

Maybe I'm being a bit too nitpicky, but that is how I look at it.

imralav
Posts: 3
Joined: Thu Dec 07, 2023 8:59 am
Contact:

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

Post by imralav »

steinov wrote:
Sun Apr 23, 2023 11:25 am
Isn't option 3 also correct? Even though it is overkill, it does avoid a deadlock. Or is it because of the "must"? If that's the case, the phrasing is a bit misleading in my opinion. Is this kind of phrasing something I can expect on the exam?
I agree with the wording being tricky. It could've been worded better, because in my opinion, as it is right now, it should be accepted too.

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

Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by admin »

Option 3 says that second thread "must" call getLocks() only after first thread exits out of it. But that is not true because the second thread can also call getLocks(obj1, obj2) without worrying about the first thread and still deadlock can be prevented.
If you like our products and services, please help us by posting your review here.

andrew1584
Posts: 8
Joined: Sat Oct 28, 2023 9:27 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by andrew1584 »

Question: "Which of the following options avoids a deadlock?"
This option definitely avoids deadlock:
"The second thread must call getLocks() only after first thread exits out of it."

So option 3 is correct.
It wouldn't be correct, if question was "what is the best option" or even "what is true".

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

Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by admin »

Please go through the response above.
If you like our products and services, please help us by posting your review here.

andrew1584
Posts: 8
Joined: Sat Oct 28, 2023 9:27 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by andrew1584 »

Those response is wrong, because it considers answer only, but ignores context(question).
Logically question can be rewritten for every option:
Will this option avoid a deadlock: "The second thread must call getLocks() only after first thread exits out of it."? It is a simple yes/no question and answer "NO" is obviously wrong. So either answer is "Yes" or question has bad wording.

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

Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574

Post by admin »

If the option had said, "A deadlock can be avoided if the second thread calls getLocks() only after first thread exits out of it", then it would have been correct.

But anyway, since it is causing confusion, we will rephrase it. Although, given that you have to pick only one option, Option 2 is clearly the best option.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 27 guests