Hi,
would it be wrong to use this as monitor for synchronization (including invocation of wait and notifyAll) instead of data?
Thanks
About Question enthuware.ocpjp.v8.2.1536 :
Moderator: admin
-
- Posts: 5
- Joined: Wed Feb 25, 2015 4:11 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1536 :
Yes, that would be wrong. You cannot use this to synchronize in this situation because this in Producer class will refer to the Produce instance and this in Consumer class will refer to the Consumer instance. For two threads (Producer and Consumer) to access the same shared resource (which is data in this situation), they need to synchronize on the same lock. That is why synchronizing on "data" is correct here.
HTH,
Paul.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 3 guests