aspose 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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

Pawel Pawlowicz
Ranch Hand

Joined: Apr 18, 2013
Posts: 596
    
  11

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

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

Pawel Pawlowicz
Ranch Hand

Joined: Apr 18, 2013
Posts: 596
    
  11

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: 593
In my unlock method, I have something like:

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1966
    
    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
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

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: 4910
    
  10

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: 1966
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unlocking an unlocked record
 
Similar Threads
record lock&unlock
No need for a locking manager?
recNo choice
B&S 2.3.1 - Identifying clients uniquely in RMI
Questions regarding locking