停止后无法启动RMI服务器

时间:2011-06-13 14:57:13

标签: java rmi

我在停止后重新启动RMI注册表时遇到问题:

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;
import javax.swing.JOptionPane;

public class CinemaServer
{
    private Registry registry;
    ClientImpl clientImple; //remote interface implemented class
    private static String title="Cinema Pvt Ltd";

    public CinemaServer() {
        try {
            clientImple = new ClientImpl();
            registry=LocateRegistry.createRegistry(3311);
            registry.rebind("RMI_INSTANCE", clientImple);
    } catch (RemoteException e) {
            JOptionPane.showMessageDialog(null, "Can't Start RMI Server",title,JOptionPane.ERROR_MESSAGE);
        }
    }

    public void stopServer()
    {
        try {
            registry.unbind("RMI_INSTANCE");
            UnicastRemoteObject.unexportObject(clientImple, true);
        } catch (NotBoundException e) {
            JOptionPane.showMessageDialog(null, "Can't Stop Server",title,JOptionPane.ERROR_MESSAGE);
        }
    }
}
  1. 我使用:CinemaServer ser=new CinemaServer();

  2. 启动服务器
  3. 当我致电ser.stopServer();时,它会停止。

  4. 但我无法重启

  5. 我得到了:

    java.rmi.server.ExportException: internal error: ObjID already in use
    at sun.rmi.transport.ObjectTable.putTarget(Unknown Source)
    at sun.rmi.transport.Transport.exportObject(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.exportObject(Unknown Source)
    at sun.rmi.transport.tcp.TCPEndpoint.exportObject(Unknown Source)
    at sun.rmi.transport.LiveRef.exportObject(Unknown Source)
    ...
    

1 个答案:

答案 0 :(得分:16)

在重新导出对象时,createRegistry()的调用失败。不要两次创建注册表。