File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Unlocking an unlocked record Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Unlocking an unlocked record" Watch "Unlocking an unlocked record" New topic
Author

Unlocking an unlocked record

Paweł Baczyński
Bartender

Joined: Apr 18, 2013
Posts: 844
    
  14

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?


Formely Pawel Pawlowicz
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 723
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

Joined: Apr 18, 2013
Posts: 844
    
  14

I'm asking what should happen if someone tries to do:



1. nothing?
2. an Exception?
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 723
In my unlock method, I have something like:

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

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


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

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.


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: 5139
    
  12

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.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Unlocking an unlocked record
 
Similar Threads
No need for a locking manager?
Questions regarding locking
record lock&unlock
recNo choice
B&S 2.3.1 - Identifying clients uniquely in RMI