Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

How to close java RMI connection?

Thread view: 
nadmasl@mail.ru - 01 Apr 2006 05:20 GMT
I have seen many examples how to close sockets but nothing about how to
tear down RMI client/server connection properly. Is there a way to do
this graceously? In the server code below, I exit by invoking
System.exit(1) but it doesn't close objects.

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class ServerRMI {
     public static void main(String[] args) {
         boolean shutdown = false;
       try {
        Server obj = new Server();
         registerToRegistry("Server", obj);
         System.out.println("Server " + obj + " started");
       } catch (RemoteException ex) {
         ex.printStackTrace();
       } catch (MalformedURLException ex) {
         ex.printStackTrace();
       }
       SimpleIO.prompt("To close RMI server type \"close\": ");
       String command = null;

       while(!shutdown){
           command = SimpleIO.readLine();
           if (command.equals("close")){
                         shutdown = true;
               System.out.println("Server is shutting down...");
               System.exit(1);
           }
       }

     }

     public static void registerToRegistry(String name, Remote obj)
                    throws RemoteException, MalformedURLException{
        if (name == null) throw new IllegalArgumentException(
             "registration name can not be null");
           try {
           Naming.rebind(name, obj);
           }
           catch (RemoteException ex){
                Registry r =
               LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
               r.rebind(name, obj);                     
           }   
         
      }

}
EJP - 03 Apr 2006 01:53 GMT
> I have seen many examples how to close sockets but nothing about how to
> tear down RMI client/server connection properly. Is there a way to do
> this graceously? In the server code below, I exit by invoking
> System.exit(1) but it doesn't close objects.

I do not understand. System.exit() closes everything.

However have a look at UnicastRemoteObject.unexportObject().

The connection between an RMI client and server is implicit and it
closes itself automatically via a short idle timeout.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.