This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronizing on data structure/object in data structure

 
Jared Chapman
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Oricio Ocle
Ranch Hand
Posts: 284
Debian Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic