• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unlocking an unlocked record

 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm asking what should happen if someone tries to do:



1. nothing?
2. an Exception?
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my unlock method, I have something like:

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic