Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Providing a safety net for lock/unlock

 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Roel De Nijs
Sheriff
Posts: 9780
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic