This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lock/unlock template Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Lock/unlock template" Watch "Lock/unlock template" New topic
Author

Lock/unlock template

Danny Martin
Greenhorn

Joined: Aug 26, 2005
Posts: 5
Hi all,
I'm still worried about the marking of Thead-safety policy: I've read some threads here in javaranch and I allow myself to submit the template I currently use in my code.

Obv., I adopts the DBAdapter pattern and so no. Each time I refer to the Data instance I do something like this:





This template ensures that each time a lock() is called, its unlock() will be called at the end of the method, whatever the exceptions raised from within the try block (which are also declared in DBAdapter method signature).

Of course, there could be some issues if either lock or (specially) unlock would raise some exceptions, but I simplified these methods in Data to remove the RecordNotFoundException declaration, since this will be raised from other calls to Data methods (e.g.: data.read(recNo)): this allows the locking of a new recNo, for example.


I'm misunderstanding this somehow. I believe that if you do that, you cannot implement the interface that Sun gave you, which I understand will cause instantaneous failure.

Well, I removed it only from Data class, not from DBMain interface!

I'd appreciate any comments about this template.

Thanks guys.
DM
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Lock/unlock template