About Question enthuware.ocpjp.v8.2.1536 :

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

Moderator: admin

Post Reply
digitalillusion
Posts: 5
Joined: Wed Feb 25, 2015 4:11 pm
Contact:

About Question enthuware.ocpjp.v8.2.1536 :

Post by digitalillusion »

Hi,

would it be wrong to use this as monitor for synchronization (including invocation of wait and notifyAll) instead of data?
Thanks

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

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

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests