"It can because the lock of gatekeeper is free"
Maybe: both threads use the same lock?
About Question enthuware.ocpjp.v8.2.1614 :
Moderator: admin
-
- Posts: 7
- Joined: Fri Dec 11, 2015 6:50 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1614 :
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.
The lock is now free and can be acquired by the second thread.
-Paul.
-
- Posts: 1
- Joined: Mon Jun 25, 2018 2:21 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1614 :
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?
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?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1614 :
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.
Who is online
Users browsing this forum: No registered users and 9 guests