File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lock concern

 
kevin ou
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Lee
Ranch Hand
Posts: 2545
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic