GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes lock concern 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 "lock concern" Watch "lock concern" New topic
Author

lock concern

kevin ou
Greenhorn

Joined: Feb 15, 2003
Posts: 23
hi All,
I have two questions in my mind about the lock.
First is that, should I use the queue to hold the
clients, because the notifyAll() may result some starving situation right?
Second is that how I can indicate that client has been expired(time out) during his booking.
Thanks guys
kevin
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Kevin,
should I use the queue to hold the clients?

I didnt bother - every client just goes into wait(). and then tries to aquire it's lock when notifyAll() gets called. In the case where there are hundreds of clients all trying to modify the same record, then it is possible that one of them might wait indefinately while others come and go, however I did not do try and handle this.
I know other people have made queues to handle this though, so it is up to you.
how I can indicate that client has been expired(time out) during his booking?

Which assignment are you doing? In FBNS, this is not allowed - the lock is a blocking call.
If you do want to do this, just throw an Exception. The client can then catch it, and decide whether to try again or not.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
I didnt bother - every client just goes into wait(). and then tries to aquire it's lock when notifyAll() gets called. In the case where there are hundreds of clients all trying to modify the same record, then it is possible that one of them might wait indefinately while others come and go, however I did not do try and handle this.
If there are hundreds of clients vying for the same record lock, then the requirements for this assignment leave much to be desired. This is a simple client/server app and I agree with Andrew, just let the chips fall as they may when notifyAll() is called.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
I have no queue in my design. just the plain lock()/unlock() function. i acknowledge there are too much i can improve.
kevin ou
Greenhorn

Joined: Feb 15, 2003
Posts: 23
hi Andrew
I think my second question is that in some situation, if a client connect to the server and doing the booking, however he may be kicked of by his ISP, then the record will be lock forever. So I may ask you if that will be also a concern for this project FBN?
Thanks
kevin
kevin ou
Greenhorn

Joined: Feb 15, 2003
Posts: 23
Sorry, let me clearify the previous message a bit.
If the client for some reason is locking the record for the long period, so the server needs to handle this kind of situation by setting the time limits for each client in order to know the client has been time out. Do we need to implement this too?
Also I would like to know that what will happen when the server is shutting down. Do I need to give the server a shutdown period?
Thanks
kevin
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Kevin,
I suggest you look at Unreferenced. In my code, if the client is disconnected, then Unreferenced gets called, and I release any locks owned by the client that just disconnected.
I did have a fun bug where two clients disconnecting simultaneously (pulled the network cable ) where one was waiting on the lock of the other one. By pure luck, the server called unreferenced on the one owning the lock first (which released it's lock) then called unreferenced on the one waiting for the lock - it had time to lock the record, but not enough time to update the fact that it now owned the lock (it wasnt in a synchronized block) - all of a suden an orphaned lock! :roll: Threw a synchronized loop around the problem code, and the problem disapeared.
Regards, Andrew
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Kevin,
Also I would like to know that what will happen when the server is shutting down. Do I need to give the server a shutdown period?
I didnt give a shutdown period. I try to get a lock on the entire database, and when I succeed I do a shutdown.
I also put a message on screen that this could hang if there is an unresponsive client, and that the user could force the shutdown if they felt is was safe.
I kind of like your solution, but I think it would require a seperate thread for me, since I have the lock() as a blocking function. So I could have a thread try and get the lock, and have the main thread wait for 30 seconds for the lock to succeed, or just shutdown anyway if the lock fails.
Regards, Andrew
kevin ou
Greenhorn

Joined: Feb 15, 2003
Posts: 23
Thanks Andrew
It seems to me that you did take care of the time out concern. Mostly what I think of server side for this project is that yes it is not require to implement every concern yet you can get the full score. However, is it true when comes to general concern, they will deduct points if you didn't write it down in your documentation? Or may be you really need to implement to get the full score?
kevin
 
GeeCON Prague 2014
 
subject: lock concern