prosseek prosseek - 2 months ago 30
Java Question

Java RMI application doesn't quit

I have a Java RMI application. The issue is that when I invoke RMI methods, and then finish the code. The application does not end.

In command line, "Bye" message is shown, but it doesn't show the prompt line.

public static void main(String args[]) throws Exception {
System.setSecurityManager(new RMISecurityManager());
s = (Registry) Naming.lookup("rmi://localhost/Registry");
ChatClientImpl c = new ChatClientImpl(name);
System.out.println("Bye"); <-- "Bye" message is shown

I have to ^C to make the application stop.

The act() method parses use's input to invoke other methods. However, even when I just quit without invoking any other methods, Java doesn't quit.

What might be wrong? Do I need to call extra methods in order to quit RMI applications?


It looks like ClientImpl is a remote object and it is still exported, so the JVM won't exit until you unexport it, with UnicastRemoteObject.unexportObject().

If that's so, I don't know why ClientImpl even is a remote object. You're not doing anything remote with it. You're not doing anything remote with anything here except the Registry. I think you have something back to front. You should be calling remote methods on the remote object s that you looked up.