About Question enthuware.ocpjp.v8.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
schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

About Question enthuware.ocpjp.v8.2.1574 :

Post by schchen2000 »

The second thread should call getLocks(obj1, obj2)
The 2nd thread can be called without having the need to wait for the 1st thread to finish.

When the 2nd thread calls getLocks(obj1, obj2) and it's assumed that an OS lets it quickly "follow" the 1st thread, it will have to wait for the the 1st thread to finish as the 1st thread goes into getLocks() and both obj1 and obj2 are locked, i.e. the 1st thread "owns" them.

When the 1st thread finishes, it releases both obj1 and obj2 and the 2nd thread will then go in.

Is my understanding correct? Thanks.

Schmichael

P. S.
The second thread should call getLocks() only after first thread exits out of it.
This is also an equally valid way/answer to avoid a deadlock, isn't it?

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

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

Post by admin »

1. Yes, that is correct.
2. It will avoid a deadlock but it is not the only way to avoid a deadlock.
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.1574 :

Post by schchen2000 »

admin wrote:1. Yes, that is correct.
2. It will avoid a deadlock but it is not the only way to avoid a deadlock.
Thanks a lot. Have a wonderful day to you.

Schmichael

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

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

Post by dvc1190 »

Will there really be a question like this where 2 answers are equally valid, but only one is counted as correct?

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

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

Post by admin »

Not equally but yes, you may get questions where two options can be reasonably argued for but you have to select only one. You have to select the best option.
If you like our products and services, please help us by posting your review here.

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

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

Post by dvc1190 »

admin wrote:
Thu Oct 17, 2019 8:42 pm
Not equally but yes, you may get questions where two options can be reasonably argued for but you have to select only one. You have to select the best option.
"Best" is extremely subjective here. Is there a reliable reason to consider the answer to this question as better than the other answer? I don't need your opinion. I need a reason that I can count on using in the actual test.

I know that if I or one of my co-workers came across a method that could cause a deadlock simply by the order or arguments, I'd recommend that the method be synchronized or otherwise made thread safe even it it defeated the purpose of the method. The danger of a deadlock isn't worth the risk. Therefore, the "best" answer is that the second thread is called only after the first thread exits out of it.

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

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

Post by admin »

No two options are equally correct in this question so I am not sure what are you confused about. "The second thread should call getLocks() only after first thread exits out of it." is not correct because, based on the given code, there is no way for the second thread to know whether the first thread has exited out of the method.

There is only one correct option and that is option 2 , "The second thread should call getLocks(obj1, obj2)". There is no ambiguity about it. This is the only valid option.

This is not a subjective opinion but a fact.

And yes, you may get a question in the exam where you may feel that two options are equally correct but 1. read the question and the options again, you will most likely find a difference that will let you pick the right option. 2. If you still feel the question has two equally valid options, go with what you feel might be the better one. There is nothing anyone can do about it other that giving your feedback to Oracle about such question. From our experience, we can tell you that such questions are extremely rare.

HTH,
Paul.
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 17 guests