File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Blocking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Blocking" Watch "Blocking" New topic
Author

Blocking

Nagu Rathina
Ranch Hand

Joined: Jun 17, 2002
Posts: 31
Ref : "The lock method should block until the requested lock can be applied"
what does it mean by block? should the client wait indefinitely till the other releases the lock? or can I just give message to client that "cannot lock record. try later." & let it proceed furthur...
Pl clarify me.
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
The client should wait until the other client releases the lock.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
the client should wait indefinitely.
pseudocode:

[ July 30, 2002: Message edited by: Erick Reid ]
Nagu Rathina
Ranch Hand

Joined: Jun 17, 2002
Posts: 31
Thank u all.
Nagu Rathina
Ranch Hand

Joined: Jun 17, 2002
Posts: 31
if a client blocks, when it requests for lock, what should I show in the client GUI? Now, it is just hanging....becoz I call wait()...
Lock DB:
In server GUI, I have a button for locking DB. if it is clicked, all clients requesting lock will hang....
Should I remove this button?
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
My client application just waited with a busy cursor. It would have been better to display a "please wait" message and prevent further screen entries.
Nagu Rathina
Ranch Hand

Joined: Jun 17, 2002
Posts: 31
should I call Lock(-1) before server is shut down? is it better to do it instead of providing a button for it?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
You should absolutely lock the database before shutting down the server. If you don't you could leave a client hanging forever waiting to lock a record or possibly even corrupt the database or allow the client to believe that a flight was booked that really wasn't (that one's a long-shot). So have your server call lock(-1) before shutting down.
Michael Morris


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
Nagu Rathina
Ranch Hand

Joined: Jun 17, 2002
Posts: 31
My client application just waited with a busy cursor...........
Do u call lock() using a seperate thread?
I use LockManager for implementing lock()& unlock. when my GuiController calls lock(recnum), it goes to LockMgr thru RemoteDataAccess. when other client has locked, I call wait(). The thread takes control of everything and my Gui becomes fully white. when lock is released and it comes out of wait(), gui shows everything properly. what should I do to avoid this prob?
Thanks Michael for lock(-1).
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Yes, locking should occur on a thread other than the swing event thread for exactly the reason you state. I'm not real clear on your design, but you probably need to utilize a Facade pattern to separate the GUI from the database. In other words, you really shouldn't make calls to the RemoteDataAccess implementation from a GUI (swing) object.
Hope this is helpful,
Michael Morris
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

You should absolutely lock the database before shutting down the server.

I didn't have server GUI, didn't have graceful shutdown (it was just Ctrl-C), and didn't lock the database before shutdown. And I still got full score for the server. I would say all these features are the extras that do not add anything to your design extendibility.
Eugene.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
So Eugene,
What happens when twenty clients are waiting for the same lock and the server ungracefully dies, leaving them hanging? I've been programming for thirty years and you don't know the hate mail I would get if I released a client-server app that at a minimum at least prevented further locks to occur and waited for all pending locks to be relinquished before closing the server.
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blocking