aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Providing a safety net for lock/unlock 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 "Providing a safety net for lock/unlock" Watch "Providing a safety net for lock/unlock" New topic
Author

Providing a safety net for lock/unlock

Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
hi

I'm thinking of providing some "tool" to make sure I release the lock after use.

It would be something like this:


then a use case would be something like this:


I would do a similar class WithReadLock

Do you think it's a stupid idea or too complex ?

I actually like the way it frees the developer from wondering about "did I properly lock/unlock ?"



++
norbert
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

Howdy, Norbert!

Well champ, so your goal here is to make sure you release your lock after its use, right? Well, you can achieve this goal with the classical synchronization or with a ReentrantLock, for instance. So it would be better to use what the Java language already provides natively. Knowing the API is also a scoring criteria. Also, using an implementation that is offered by the language is prefered over an own implementation that would do something similar. So I'd say that you are introducing an unnecessary complexity. My advice would be to keep things simple and use what the language already provides. Most of us that passed this certification achieved this goal without providing our own implementations!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5610
    
  15

I think it doesn't add any value. If you would create some kind of framework, it is important to make the developer (user of your framework) to do a lot behind the scenes (so the developer can focus on real business logic instead of boilerplate code). But now you just have 2 methods which need to be enclosed in a lock/unlock sequence, so in my opinion that's killing a mosquito with a hammer.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
Howdy

This stuff is just on top of the API, to make sure one doesn't forget to do the lock/try/finally/unlock. But then, in the end, it doesn't provide much, esp since there's no way I can force the developer to use it, and is quite some boilerplate code. So I'll just skip it. Sorry for the noise and thanks for your answers.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

Norbert Lebenthal wrote:Sorry for the noise and thanks for your answers.


Come on, champion! We are all here to exchange ideas and help each other!
 
wood burning stoves
 
subject: Providing a safety net for lock/unlock