• 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

public void lock(-1) for what ?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The specs ask that if -1 is passed into the lock method then the entire database is locked. As I was reading GUI specs I did not find anywhere, where lock(-1) would be used directly or indirectly. Why is there this lock(-1) requirement if it is not used. Can somebody help me understand.
Thanks,
Sanjeev
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No confusion. When u implement locking u do API - so they demand to add ability to lock the whole database. On the other hand when u write the client u follow the GUI requirements and there is no such one there. lock(-1) is very simple - just lock one by one in a loop. Unlock(-1) acts in the same way
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think it's too simple, i'm working on locking methods now and when some thread try to lock(-1) and some record is already locked by another client, it will have to wait until all the records are free to be locked.
[Eduz]
 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure you need to lock all records by when doing the lock(-1). Maybe its easier to just put it in a map and any other connection trying to get the lock first sees if the database is locked or not before obtaining the lock.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only place where lock will be called with a -1 is from the server, when it wants to shutdown.
the server cannot shutdown when a client has a lock, so waiting till all the clients unlock their record is worth the wait.
I'll let you guys work on the rest
Mark
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Mark. Though not requested now, maybe even adding a record or deleting a record would require a database level lock. This ofcourse is beyond the scope of the application.
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only place where lock will be called with a -1 is from the server, when it wants to shutdown.
the server cannot shutdown when a client has a lock, so waiting till all the clients unlock their record is worth the wait.
Mark, I have a question, well if the server tries to wait on all locks present being cleared, whats to prevent some other thread from asking new locks and it getting it, therby starving the thread that requires a database only lock??? This is a possiblility.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really. Yes if I get to record #10, in my lock(-1), and client a has a lock on 10, and while waiting, client b locks 12, then client a unlocks 10, well then we get to record 12, then we wait again until client b unlocks 12. It will even if the client disconnects, because the RemoteInterface also implements the Unreferenced Interface, so it will always unlock the record it had locked, and the server can go on it's merry way
Mark
 
Roman Rytov
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me a discussion about where, when and whom lock(-1) might be called doesn't leed us to any decision. The requirement of this syntax is a part of the instuctions and its implementation is straightforward. Why should we worry? The point cause of which we may loose some marks in the exam is loosing simplicity. Make a loop and lock all records one by one. I'm sure it works fine.
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes mark, I see what you mean. But if requests keep coming for locks there is no gurantee that the lock(-1) will succeed.
 
You showed up just in time for the waffles! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic