GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes database unlock() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "database unlock()" Watch "database unlock()" New topic
Author

database unlock()

Venkatesh Krishnappa
Greenhorn

Joined: May 26, 2003
Posts: 16
Hey,
Iam doing the FBN assignment. have few questions about the database unlock.
1. The requirement doesn't talk about *unlocking* the entire database. so what do we do after locking the entire database successfully ?
should we just print a log and return ?
A client may lock the database for the purpose of doing changes to the database and may want to release the lock right after it without restarting the server. In this scenario don't we need the database unlocking implementation ?
if the purpose of locking the database is only for shutting down the server, then I agree there's no point in having database unlock.
2. My implementation of database locking waits for all the record level locks to expire and rejects new lock requests by throwing an exception.
please let me know your comments.
-venky
Marcos Motta
Ranch Hand

Joined: Apr 28, 2002
Posts: 56
Venkatesh,
1) I have implemented unlock(-1) just like regular record lock. One of possible uses for it is shuting down, but there might be others, like put the database in maintenance mode, do some work and release it to the clients.
2) In my implementation, lock(-1) has priority over regular record locks. lock(-1) waits for all record locks to be released and, during this time, blocks new lock requests instead of throwing exceptions.
But I havent submitted my assignment yet...
Marcos
Patrick Cobbett
Ranch Hand

Joined: Jul 10, 2003
Posts: 44
Marcos, my implementation of lock(-1) is just built on top of lock(!-1), meaning it sequentially locks each record starting from the beginning. If all clients performing a full database lock start from the first record, then there is no danger of deadlock, as only the client which obtains the first record lock will suceed until it has released all the locks.

In my implementation, lock(-1) has priority over regular record locks. lock(-1) waits for all record locks to be released and, during this time, blocks new lock requests instead of throwing exceptions.

Certainly the requirements says that methods to lock an already locked record should block and not throw an exception.


[SCJP, SCJD]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Venkatesh
The requirement doesn't talk about *unlocking* the entire database. so what do we do after locking the entire database successfully ?
should we just print a log and return ?

All you need some way of indicating that the entire database is now locked. You could do it like Marcos and grant a lock on record number -1 or you could do it like Patrick and lock each individual record. I don't see any problems with either option - they will both eventually work.
Once you have done that, it is up to the client who locked the entire database to decide what to do next.
A client may lock the database for the purpose of doing changes to the database and may want to release the lock right after it without restarting the server. In this scenario don't we need the database unlocking implementation ?
if the purpose of locking the database is only for shutting down the server, then I agree there's no point in having database unlock.

We do not know what purpose the architect planned for locking the entire database. I chose to allow the entire database to be unlocked again just in case the architecht has some other use aside from shutting down the server.
My implementation of database locking waits for all the record level locks to expire and rejects new lock requests by throwing an exception.

I also waited for existing locks to be released before granting the database lock.
Like Marcos, I gave database locks priority over record locks.
But I did not throw an exception for new attempts to lock a record - they just blocked. Again, not knowing why the database was locked, I did not know if it would eventually be released in which case the individual record locks could be aquired.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Venkatesh Krishnappa
Greenhorn

Joined: May 26, 2003
Posts: 16
Thanks so much for your answers.
-venky
 
GeeCON Prague 2014
 
subject: database unlock()