File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Disconnecting an RMI connection 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 "Disconnecting an RMI connection" Watch "Disconnecting an RMI connection" New topic

Disconnecting an RMI connection

David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
I don't have much experience with RMI, so I have a dumb question: In the Registry interface of RMI is the "unbind(String name)" method used to disconnect a client from a server without shutting the server down? Would this be the way to swap between remote servers for a client, or swap between standalone and remote modes? If I swap between modes, I don't want to shut the server down until the user shuts it down. I guess I would just do a rebind to get an RMI connection back to the desired server?

Any input is again appreciated. Thanks a lot!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Hi David,

The unbind method is designed to be used on the server side - it removes the specified method from the registry of methods that can be called remotely. If the 'force' parameter is false, this will only remove the specified method from the registry - it will not disconnect any currently connected clients.

From the client side, if you wanted to change servers, all you need do is remove your current reference to the remote method (set it to null) and do a lookup for an alternate method and/or on an alternate server (or implicitly do both at once by just setting your reference to the new looked up value, which will automatically make your old value eligible for garbage collection).

I believe it is better to explicitly set the reference to the remote method to null, then call the garbage collector. This will result in the distributed garbage collector knowing that the client has disconnected earlier, which means that Unreferenced and/or WeakHashMap code can be called earlier. But this is all dependant on the operations of the garbage collector and the distributed garbage collector, which, as we know, is all a black box and cannot be relied on. So this is just a technicality.

Regards, Andrew

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

Joined: Apr 19, 2005
Posts: 61
Hi Andrew,
Thanks a bunch for your reply. Now I better understand how to swap servers and/or modes. Appreciate it.
jQuery in Action, 3rd edition
subject: Disconnecting an RMI connection
It's not a secret anymore!