About Question enthuware.ocpjp.v8.2.1614 :

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

Moderator: admin

Post Reply
surzhin
Posts: 7
Joined: Fri Dec 11, 2015 6:50 am
Contact:

About Question enthuware.ocpjp.v8.2.1614 :

Post by surzhin »

"It can because the lock of gatekeeper is free"

Maybe: both threads use the same lock?

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

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

Post by admin »

I am not sure what you mean. The previous sentences explain that the lock become free, "the first thread gets the lock of gatekeeper object and enters the ///if()/// block. It then calls ///gatekeeper.wait()///, thereby releasing the lock and entering into a wait state.".
The lock is now free and can be acquired by the second thread.
-Paul.

mirelav
Posts: 1
Joined: Mon Jun 25, 2018 2:21 pm
Contact:

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

Post by mirelav »

Hi,

But if we create two different threads, does this not mean that we create a gatekeeper object for each of them, therefore the run method is basically not synchronized? Each of the threads would have its own lock, or am I misunderstanding something?

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

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

Post by admin »

You probably missed the fact that gatekeeper is static. So no matter how many TestClass objects you create, the gatekeeper reference will point to the same instance of Object and so both the threads will use the same object to synchronize.

Post Reply

Who is online

Users browsing this forum: admin, Bing [Bot] and 7 guests