*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI object life time??? 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 "RMI object life time???" Watch "RMI object life time???" New topic
Author

RMI object life time???

J Hartley
Ranch Hand

Joined: Mar 29, 2001
Posts: 52
Hi, please help me in my understanding....
(assume Unicastremoteobject)
I have an RMI server that creates an instance of object X and then registers X with the registry.
Client A binds to this object X
Client B binds(rebinds?) to this object X
Both clients are very happy and call methods of object X
The server is still running(how? its went out of its main() didnt it???) .if the server dies so does the object instance X right?
Both clients exit. And implicity no longer reference the instance.
Now, the big question!, because no clients reference X, does it get garbage collected???. if not, does this this mean that if the server that created X is running than it will not get garbage collected.
if it does get garbage collected, what if client C come along and class bind ro rebind?...well x doesnt exist!, what happens then?
All help much appreciated!!!
Joe
Aleksey Matiychenko
Ranch Hand

Joined: Apr 03, 2001
Posts: 178
I believe that RMI server does not get gargbadge collected just because it does not have any clients. This would defeat the purpose of RMI (having client and server separated).
If the server dies then the client won't be able to connect to it Unless the server was using Activation framework.
IF the server was Activatable then an instance of it would only be used during a client request.
Alex
R Bischof
Ranch Hand

Joined: Feb 13, 2001
Posts: 48
Joe,
at the time you bind a server object X to the registry using the name "ObjectX", that object gets exposed to the outside and is never garbage collected since the registry has a handle on it. It does not matter if any clients access the object or not. You can always use the naming stuff to look up the registered object X with the name "ObjectX".
Things are different if your registered object X has a method that returns a handle to another remote object Y to your clients. If object Y is not bound to the registry, the only references to this object are the remote reference from your clients. If your clients stay alive and have a valid (remote) reference to Y, it is not garbage collected. If your clients die or do not permanently hold the reference to Y the distributed garbage collector removes collects Y a few minutes later.
This is also true if your client object which holds the remote reference is itself no longer used and garbage collected.
HTH
Rainer


Rainer<br />SCJP, SCJD, SCWCD
J Hartley
Ranch Hand

Joined: Mar 29, 2001
Posts: 52
Hey, thanks for explanations chaps.
Cheers
Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI object life time???
 
Similar Threads
NX:WeakHashMap, simple question
RMI Server becoming unreferenced
Remote object life time?
rmi Client-Server
Client Side Garbage Collection !