aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes A small issue about unreferenced Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "A small issue about unreferenced" Watch "A small issue about unreferenced" New topic
Author

A small issue about unreferenced

Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi guys,
There is an issue that needs to be tackeled.
I have implemented my locking mechanism using LockManager using the remote object as the connection identifier. I have ConnectionManager instance binded to the rmireigstry. The clients can get access to RemoteData by calling its getConnection() method. The RemoteData extends the UnicastRemoteObject and implements a remote interface.
To cleanup dead client's locks on database I maintain a HashSet that keeps track of all records locked. That is if a record is locked an Integer object for the record number is added to the hashset. If a record is unlocked that the Integer object for that record number is removed from the hashset.
My RemoteData class implements Unreferenced. So, Whenever the RemoteData object is unreferenced I call the releaseClientLocks() method which iterates through each record locked by this client (achieved by the HashSet already discussed) and unlocks them.
I have also added a finalize() method which when called also performs the same operation as that of unreferenced.
Now, the problem is that till now I have not been able to verify that these algorithms for clearing dead client's lock work. Is there any way to cause the Unreferenced situation to be invoked ??
Is there any problem with the above implementation??
Any suggetions....
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Create a standalone client and spawn multiple threads to simulate multiple clients. From each of these threads, you lock certain record and don't call unlock(). Wait for about 15 mins and you will see the unreferenced() being invoked by the RMI runtime at the server.
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi Sai,
I will try it and keep you posted.
I heard from you after a long time. How are u doing?
Vishal
parthiban subramaniam
Ranch Hand

Joined: May 15, 2002
Posts: 116
Hi,
from what i understand .. unreferenced is not meant for a specific client who holds a stub for this rmi object but for the whole .. the unrefrenced method is invoked by the rmi system when the the no of remote client to this rmi object falls to 0 ..then how are your removing record locks which are locked by this client ??
quote==================
My RemoteData class implements Unreferenced. So, Whenever the RemoteData object is unreferenced I call the releaseClientLocks() method which iterates through each record locked by this client (achieved by the HashSet already discussed) and unlocks them.
===============
in my opinion if such a situation occurs then we can just pass a message to clear all the locks in the lockmanager for this rmi object same applys to finalize .. i wuld sugest you to kill all the clients and wait for sometime to see how it all goes .. or just trust the specifications
cheers,
parthi.


Even crazy and silly looking problems are sometimes real.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

Originally posted by parthiban subramaniam:
from what i understand .. unreferenced is not meant for a specific client who holds a stub for this rmi object but for the whole .. the unrefrenced method is invoked by the rmi system when the the no of remote client to this rmi object falls to 0 ..then how are your removing record locks which are locked by this client ??

Your understanding is correct about how the RMI runtime determines when to call unreferenced. If you have issued a unique connection to each client then it is obvious which client owns the locks held by the Unreferenced object. There can never be more than one remote reference in such a situation, so when the client dies the reference count falls to 0.

Originally posted by Vishal Sinha:
I have also added a finalize() method which when called also performs the same operation as that of unreferenced.

Bad idea. You don't need a finalize() method. Let GC, DGC and Unreferenced take care of everything for you. Unreferenced is going to called by the DGC anyway, so why do you need finalize()? Just let the object die gracefully when the client connection fails.
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A small issue about unreferenced
 
Similar Threads
Networking : RMI
FBNX: Locking, clientID and deadlock...
Mark Spritzler/ Max H/Andrew Monkhouse: please comment on the holes in my design
why remote object is still alive after unreferenced()?
please comment ! my design of local/remote and lock