我有以下使用Java的设置:
private static ServerInterface serverInterface;
private static Registry serverRegistry;
public static void main(String[] args) {
try {
serverRegistry = LocateRegistry.getRegistry(serverAddress, serverTCPPort);
String[] rpcList = serverRegistry.list();
serverInterface = (ServerInterface) serverRegistry.lookup(rpcList[0]);
debugPostIt("Server communication test succeeded.");
} catch (RemoteException | NotBoundException e) {
postIt("The specified server is not available!");
System.exit(1);
}
<< Some code that calls methodA() and methodB(Object o)>>
}
private boolean methodA(){
try{
serverInterface.someMethodA();
}catch(RemoteException e){
System.out.println("Communication fail in A.")
}
}
private boolean methodB(<<params>>){
<<Create a new object based on B>>
try{
serverInterface.someMethodB(Object o); // o is not Serializeable.
}catch(RemoteException e){
System.out.println("Communication fail in B.")
}
}方法A每次都成功,但是方法B每次都抛出一个RemoteException,即使运行接口的进程没有停止。无论发出什么命令,A总是成功,B总是失败。当我将someMethodB更改为methodB中的someMethodA时,methodB不再失败。我在远程对象端进行了简单的检查,以查看方法是否正在被访问,而它没有被访问。有人能告诉我这里可能发生了什么吗?
编辑:是否需要在RMI方法中传递对象,比如对象必须是可序列化的,或者类似的东西?
发布于 2014-03-27 18:36:39
谢谢你回答我自己的问题!
我对someMethodB()的输入参数是一个泛型对象,我创建的对象还没有实现可序列化。将这个点添加到类中解决了这个问题。编辑的问题,以更准确地显示问题。
http://docs.oracle.com/javase/tutorial/rmi/implementing.html
https://stackoverflow.com/questions/22695797
复制相似问题