• Post Reply Bookmark Topic Watch Topic
  • New Topic

opinions on locking and synchronized  RSS feed

Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!