• 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

hand over hand locking

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic