简体   繁体   English

Java RMI NoSuchObjectException

[英]Java RMI NoSuchObjectException

I have a server and client using Java RMI. 我有使用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 java.rmi.NoSuchObjectException:表中没有此类对象

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);

NoSuchObjectException means that the stub refers to a remote object which has been unexported, either explicitly or via GC. NoSuchObjectException意味着存根引用已显式或通过GC取消导出的远程对象。 Are you getting this on the lookup(), or the registerClient(), or the removeClient()? 您是在lookup()还是registerClient()还是removeClient()上获取此信息的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM