About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574
Moderator: admin
-
- 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
why option 1 of this question will create deadlock??
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 19
- Joined: Wed Feb 08, 2023 3:11 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 :
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?
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 :
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.
-
- 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
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.
Maybe I'm being a bit too nitpicky, but that is how I look at it.
-
- Posts: 3
- Joined: Thu Dec 07, 2023 8:59 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 :
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.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574
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.
-
- 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
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".
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".
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574
Please go through the response above.
If you like our products and services, please help us by posting your review here.
-
- 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
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.
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.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.637 : enthuware.ocpjp.v17.2.1574
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.
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.
Who is online
Users browsing this forum: No registered users and 16 guests