Java RMI NoSuchObjectException

旧街凉风 提交于 2019-12-11 12:58:33

问题


I have a server and client using Java RMI. If I use one client all is fine with the code below. But if I connect with a client and then a second one, it throws port already in use exception. That's fine, so I disconnect the connected client and then try to connect with the second client again. It gives me this:

java.rmi.NoSuchObjectException: no such object in table

Why is this?

//CONNECT

Registry registry = LocateRegistry.getRegistry(
    Options.getRegistryIp(), Options.getRegistryPort());
server = (IServer) registry.lookup(Constants.MB_SERVER_NAME);

UnicastRemoteObject.exportObject(client, Options.getMyPort());
server.registerClient(client);

//DISCONNECT

server.removeClient(client, client.getUser());
UnicastRemoteObject.unexportObject(client, false);

回答1:


NoSuchObjectException means that the stub refers to a remote object which has been unexported, either explicitly or via GC. Are you getting this on the lookup(), or the registerClient(), or the removeClient()?



来源:https://stackoverflow.com/questions/4986272/java-rmi-nosuchobjectexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!