File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes hand over hand locking 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 "hand over hand locking" Watch "hand over hand locking" New topic

hand over hand locking

Mike Hays

Joined: May 15, 2009
Posts: 14

I've read that masterLock.lock() in the following code should come before the try block because it might throw an exception. If it is placed inside the try block and an exception is thrown, the finally block will attempt to unlock a lock that isn't locked.

Can masterLock.unlock() also throw an exception? If it does then recordLock might not get unlocked. Is the following code not a correct way to implement hand over hand locking?

Mike Hays

Joined: May 15, 2009
Posts: 14
Hi all,

I'm also trying to understand how to acquire 2 locks in a row. For example,

Are either of the above approaches correct? As noted in the comments they both seem to have problems.

How about

But I've read that nested try blocks are undesirable. Anyone know how to do this correctly?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: hand over hand locking
It's not a secret anymore!