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

public void lock(-1) for what ?

 
Sanjeev Rathore
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Roman Rytov
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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
 
Eduardo Resende
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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]
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic