java 停止后无法启动 RMI 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6332141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't start RMI server after stopping it
提问by sAaNu
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);
}
}
}
I start the server with:
CinemaServer ser=new CinemaServer();
And when I call
ser.stopServer();
it stops.But I cannot restart it
我用以下命令启动服务器:
CinemaServer ser=new CinemaServer();
当我叫它
ser.stopServer();
停止时。但我无法重新启动它
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)
...
回答by jtahlborn
the call is failing on createRegistry()
, noton re-exporting your object. don't create the registry twice.
调用失败createRegistry()
,而不是重新导出您的对象。不要两次创建注册表。