File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes opinions on locking and synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "opinions on locking and synchronized" Watch "opinions on locking and synchronized" New topic
Author

opinions on locking and synchronized

Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
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.


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opinions on locking and synchronized