• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

opinions on locking and synchronized

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,
I am looking for opinions on the way I did my locking. I have a LockManager that has a HashMap of (lock, clientId) pairs. When my RemoteData asks the LockManager to do a lock, the first thing that happens is a synchronized(hashLock) is started and it has everything in the method in this synch block. Same for my unlock block.
To test my locking I put a Thread.sleep(5000) in my unlock, and it seems to be working, but I never get anything to get to the wait() line of code in the lock() method because of the syncronized(...) first line. This means that every access to modify the db is going to wait its turn even if the modifications are on different rows.
Should I try to only synch after I know there is a lock on a certain row, or leave it the way I have it? It seems that my code will never hit the hashLock.wait() and that seems bad to me.
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic