停止RMI服务器后不能启动它

时间:2022-04-02 20:54:50

I'm having a problem restarting my RMI registry after it has been stopped:

我有一个问题,重新启动我的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. I start the server with: CinemaServer ser=new CinemaServer();

    我使用:CinemaServer ser=new CinemaServer()启动服务器;

  2. And when I call ser.stopServer(); it stops.

    调用ser.stopServer();它停止。

  3. But I cannot restart it

    但我无法重启它

I'm getting:

我得到:

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 个解决方案

#1


14  

the call is failing on createRegistry(), not on re-exporting your object. don't create the registry twice.

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

#1


14  

the call is failing on createRegistry(), not on re-exporting your object. don't create the registry twice.

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