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

Unlocking an unlocked record

 
Paweł Baczyński
Bartender
Posts: 1878
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.
What should happen if someone tries to lock a locked record or unlock an unlocked record?
Well, as for locking a locked record that's simple. Just wait till a record is available.
What for a second part of my question?
I see two possible outcomes but I can't decide which is better.
(1) do nothing, because we want a record to be unlocked and it is unlocked so "mission acomplished "
(2) throw IllegalStateException because trying to unlock already unlocked record is a wrong API usage.
Any suggestions?
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Pawel,
I don't understand the question.
But to unlock a record, all you need is to signalAll or notifyAll to wake up those waiting threads.

We usually unlock a locked reocrd. If a record is unlocked, you won't get to the method of unlock.
The code should be implemented in this way in a thread :

 
Paweł Baczyński
Bartender
Posts: 1878
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm asking what should happen if someone tries to do:



1. nothing?
2. an Exception?
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my unlock method, I have something like:

 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:I'm asking what should happen if someone tries to do:



1. nothing?
2. an Exception?


I don't think it's possible to unlock twice or lock twice on any records. Because the interface file provided by Sun or should I say Oracle now does not have a lock or unlock method. The lock and unlock methods are called in your Data class.

The only possible way for your stated problem is someone changes the Data class code explicitly to lock twice or unlock twice.

Keep things simple
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Pawel!

I think that one possibility is the following: if the record exists but isn't locked, throw new IllegalStateException; otherwise, you can throw RecordNotFoundException.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:I don't think it's possible to unlock twice or lock twice on any records. Because the interface file provided by Sun or should I say Oracle now does not have a lock or unlock method. The lock and unlock methods are called in your Data class.

That's possible without any doubt! The lock/unlock methods are defined in the interface you have to implement and thus are public, so they can be invoked as many times as you want from outside the Data class.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
K. Tsang wrote:I don't think it's possible to unlock twice or lock twice on any records. Because the interface file provided by Sun or should I say Oracle now does not have a lock or unlock method. The lock and unlock methods are called in your Data class.

That's possible without any doubt! The lock/unlock methods are defined in the interface you have to implement and thus are public, so they can be invoked as many times as you want from outside the Data class.


Don't remember much about what is provided and what's not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic