Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Habibi's code example, locking and unlocking records

 
Jay Lin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm studying for the SCJD exam and looking through the code examples from Habibi's book, namely the DVDDbAdapter class. The modify DVD method goes something like this:


My question is, suppose the call to db.modifyDVD (fourth line) throws an exception. Does that mean the line which releases this DVD will not be called? My concern is that in the case of an exception (this method may also throw IOException), this DVD will never be released, and no threads from this point on can ever reserve it.

Would it be more correct to put the release code in a finally block at the end? Thanks for any info.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12012
218
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jay,

Yes, you are correct on both counts: If the modifyDVD threw an exception, the record would remain reserved. Putting the call to releaseDVD in a finally block would solve this issue.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic