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

-1 to lock the db

 
Jim Deller
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, my fbn instructions tell me:
"The lock method should block until the requested lock can be applied. The integer argument indicates the record to be locked. If the method is called with an argument of -1, the entire database should be locked."
This sounds to me like the user (evaluator) wants to lock-out any client record-updates until he or she unlocks the db.
What event should be developed to unlock the db?
thanks, Jim
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jim, welcome to JavaRanch. I'm sure someone will help you with your question "right soon now".
In the meantime you can try the search utility (near the top on the right) to search the forum for "lock unlock".
However, I must ask you to review JavaRanch's Naming Policy, and to change your displayed name accordingly. Thanks
-Barry
[ May 12, 2003: Message edited by: Barry Gaunt ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim
Other possible uses for the -1:
  • lock the entire database before shutting it down
  • lock the entire database before adding new records
  • lock the entire database when a major change to data is occuring (example: refresh from airline sources).


  • I am sure there are others.
    I set my RMI code to throw an exception if records were not locked before any changes (add / change / delete), and I did check for the -1 lock before allowing the add.
    I also set my server to read from the command line, and if the user enters "quit" then an attempt is made to lock the entire database before doing this.
    Now .... how much of this is necesary? Probably none of it. I have seen posts by people who have passed who just used Ctrl-C to kill the server process. Likewise I have seen posts by people who gave direct access to the add method without any locking. I have also seen posts by people who do the locking behind the scenes if someone calls a method which changes the database without locking first. You have to decide what you think is right, and what you are willing to code for.
    As for the unlocking of record "-1" ... I cannot see any reason not to handle it like any other unlock. All you are doing is seeing if that key is locked by the current user, and if so unlock it. There is nothing special about it.
    It is only on the locking side that you have to do extra work - blocking until the lock table is empty, and disallowing new locks.
    Regards, Andrew
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic