我有一个简单的 RMI 服务器,它将文件存储在地图中并在请求时返回它们。地图中存储的文件类型为 Object。我已经这样做了,所以我不需要导入包含存储特定文件的项目其他部分的库(还有其他方法吗?)。
由于存储的类型是对象,我不应该没有导入就可以吗?同时出现错误,我得到 java Finalizer thread crash 。这是堆栈:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: util.MyClass (no security manager: RMI class loader disabled)
Invalid memory access of location 0x0 rip=0x7fff91016390 <<< this is from crash
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:334)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
这里还有一些来自 Client 的代码:
public void uploadProjects(List<MyClass> projects) {
try {
Object obj = projects;
rmiServer.upload(channel, obj); // <<<< exception on this line
} catch (RemoteException ex) {
Logger.getLogger(RMIClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
这是接口方法:
void upload(String channel, Object projects) throws RemoteException;
我在那里做错了吗?它不应该在不需要导入特定类的情况下与 Object 一起正常工作吗?我过去也尝试过使用安全管理器,但这只会导致更多麻烦,并且必须执行 AllPermissions 才能使其工作(在其他项目上)......
崩溃并不总是发生,但它一定是由 RMI 引起的。