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 URLyBird: Timer to unlock locked records when client crash Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URLyBird: Timer to unlock locked records when client crash" Watch "URLyBird: Timer to unlock locked records when client crash" New topic
Author

URLyBird: Timer to unlock locked records when client crash

Henrik Strand
Greenhorn

Joined: Jan 05, 2006
Posts: 20
Hi all!

Have anyone here considered what will happen when a client who has locked a record crashes before it can call unlock on the locked record? Has anyone implemented a solution for it?

Regards,
Henrik

[ February 09, 2006: Message edited by: Henrik Strand ]
[ February 09, 2006: Message edited by: Henrik Strand ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Henrik,

This is a common topic here. Many candidates ignore the problem, however you will find many topics discussing using the Unreferenced interface (for RMI), WeakHashMap (for RMI or Sockets), or catching the exception when a socket disconnects (for Sockets) to handle this.

Where would you like to go with this?

Regards, Andrew


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

Joined: Jan 25, 2006
Posts: 239
Hi Andrew,
I am wondering how to use Unreferenced?


SCJP 1.4 SCJD
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Zhixiong,

Unreferenced is an RMI interface - aren't you developing a Sockets solution?

If you are using RMI, have you developed an Remote Factory so that each client gets their own Remote object?

Regards, Andrew
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi Andrew,
Before last week I used Socket, and this week i just want to try RMI.While using Socket, my server-clients can run only under assistance of multithread.And this week i found that mulity clients need not have to use multithread if i use RMI.I didnot use RMI Factory, and could you show me the advantage when using RMI Factory.

Wishes.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Zhixiong,

For your purposes, the main advantage for having an RMI Factory creating Remote objects is that each Remote object can implement the Unreferenced interface. Then, when a client disconnects (whether deliberately, because of network problems, or because of a crash) the unreferenced() method will be called, which gives you an opportunity to clean up stale (or orphaned) locks.

For candidates who do not have interfaces that use cookies, using an RMI factory also means that each client can have their own Remote object - if you take this a step further such that each Remote object has it's own Data object, then the instance of the Data object itself can be used to identify the client who has locked a record, rather than using the cookie to identify the client.

An example of using an RMI Factory and the Unreferenced interface is shown in the topic "Rmi question" - note that this does not walk you through the code, but just presents it and leaves it to the reader to ask questions.

Regards, Andrew
 
wood burning stoves
 
subject: URLyBird: Timer to unlock locked records when client crash
 
Similar Threads
The Server
NX: notify instead of notifyAll?
The Assignment Result
URLyBird: GUI: Internal Frames
URLyBird: Locking a record twice