wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Synchronizing on data structure/object in data structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Synchronizing on data structure/object in data structure" Watch "Synchronizing on data structure/object in data structure" New topic
Author

Synchronizing on data structure/object in data structure

Jared Chapman
Ranch Hand

Joined: Feb 23, 2004
Posts: 81
I'm not positive on how this would work. I have a synchronized HashMap of records called recordCache. Inside this cache I store (recNo, Record) as the key value pairs.

When I lock a record to be modified/updated/deleted, I lock on a Record and not on the entire recordCache. This way, when I unlock the record and call notifyAll(), I will only be waking up threads waiting for that particular record. There are times, however, when I want to lock the entire recordCache. So my question is, how will synchronizing on recordCache and synchronizing on an element inside recordCache effect each other?


B.S. University of Wisconsin<br />SCJP 1.4 (85%)<br />SCJD 1.4 (92%) B&S Contractors
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hi Jared!
I have a synchronized HashMap of records called recordCache

I supose you have something similar to:

and for records:

My question is: Are those blocks nested in any case?


SCJP, OCMJD, OCMJEA
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Synchronizing on data structure/object in data structure
 
Similar Threads
Locking mechanism concept questions
design question: should the lock manager be synchronized whenever it's used in Data?
Lock on reading records
multiple (non-nested) synchronized blocks in single method
Possibility of Locking a Record, that has just been deleted.