java.rmi.NoSuchObjectException: no such object in table

后端 未结 7 2296
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 06:43

I am writing a very simple RMI server, and I am seeing intermittent java.rmi.NoSuchObjectExceptions in the unit tests.

I have a string of remote method

7条回答
  •  自闭症患者
    2020-11-28 07:06

    Got the same error but probably for the other (yet unknown) reason.

    I was casting exported object to the type of my remote interface and then while binding to name I was getting NoSuchObjectException. Removing casting fixed the problem.

    Briefly:

    public interface MyRemoteInterface extedns Remote {
        ...
    }
    
    public class MyRemoteObject implements MyRemoteInterface {
        ...
    }
    
    public static MyRemoteObject obj = new MyRemoteObject();
    
    public static void main(String[] args) {
        //removing cast to MyRemoteInterface fixes the problem
        this.obj = UnicastRemoteObject.exportObject((MyRemoteInterface) this.obj, 0);
    
        //unless the above cast is removed, this throws NoSuchObjectException occasionally
        LocateRegisry.getRegistry("127.0.0.1", 1099).bind("name", this.obj);
    }
    

提交回复
热议问题