This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
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