Page 1 of 1

About Question enthuware.ocpjp.v8.2.1614 :

Posted: Tue Mar 22, 2016 7:29 am
by surzhin
"It can because the lock of gatekeeper is free"

Maybe: both threads use the same lock?

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

Posted: Tue Mar 22, 2016 9:32 am
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.

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

Posted: Sat Jul 07, 2018 5:42 am
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?

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

Posted: Sat Jul 07, 2018 6:47 am
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.