Java RMI调用远程程序抛出异常

如图所示代码,在服务器程序挂起后运行客户端程序,会抛出异常“Exceptioninthread"main"java.lang.ClassCastException:com... 如图所示代码,在服务器程序挂起后运行客户端程序,会抛出异常“Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to CustomApp.InterfaceToServerApp.RimConnecter at CustomApp.InterfaceToServerApp.RimClient.main(RimClient.java:22)”。求解怎么破 展开
 我来答
在晴天的雨伞
2016-06-02 · TA获得超过6869个赞
知道大有可为答主
回答量:5761
采纳率:86%
帮助的人:1245万
展开全部
背景要求:定时监控远程主机上mongodb数据库内存使用的情况,当内存使用过大时暂停逻辑处理线程后启动内存空间的释放处理线程,释放完成后再启动逻辑处理线程。
操作系统:CentOS 64bit (Linux)
步骤(代码省略):
1.创建Socket远程服务器
2.创建客户端
配置:
#查找对象stub端口
RMI_PORT=9902
#服务端口
RMI_SERV_RMI_PORT=9903
#注册服务地址端口要和查找对象stub端口一致
RMI_URL=rmi://192.168.0.118:9902/MongoServer
#绑定IP
RMI_IP=192.168.0.118
#检查内存shell
RMI_MEMQUERY_COMMAND=sh /home/test/BI/smartshow14/MongoDBRMIServer/memquery.sh
#释放内存shell
RMI_MEMFREE_COMMAND=sh /home/test/BI/smartshow14/MongoDBRMIServer/memclear.sh
#释放内存容量阀值,单位M
RMI_MEM_CAPACITY_LIMIT=3000
3.启动服务器
客户端线程通过 rmi://192.168.0.118:9902/MongoServer 访问时出现异常:
--定时扫描MONGODB内存线程--:开始运行!
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.linkage.iface.IMongoDBScan (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at com.linkage.querytool.QueryRMICaller.ramCapacityScan(QueryRMICaller.java:87)
at com.linkage.querytool.MongoDBARMScanThread$TimerWorkTask.run(MongoDBARMScanThread.java:94)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.ClassNotFoundException: com.linkage.iface.IMongoDBScan (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:535)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
... 6 more
--定时扫描MONGODB内存线程--:处理结束!
=======================================================================================================
--定时扫描MONGODB内存线程--:开始运行!
java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.0.118:9902 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at java.net.Socket.connect(Socket.java:524)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at com.linkage.querytool.QueryRMICaller.ramCapacityScan(QueryRMICaller.java:89)
at com.linkage.querytool.MongoDBARMScanThread$TimerWorkTask.run(MongoDBARMScanThread.java:94)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
--定时扫描MONGODB内存线程--:处理结束!
============================================================================================================
--定时扫描MONGODB内存线程--:开始运行!
java.security.AccessControlException: access denied (java.lang.RuntimePermission createSecurityManager)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.<init>(SecurityManager.java:282)
at java.rmi.RMISecurityManager.<init>(RMISecurityManager.java:45)
at com.linkage.querytool.QueryRMICaller.ramCapacityScan(QueryRMICaller.java:88)
at com.linkage.querytool.MongoDBARMScanThread$TimerWorkTask.run(MongoDBARMScanThread.java:94)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
--定时扫描MONGODB内存线程--:处理结束!

==========================================================================================================
以上异常都有可能出现,通过以下方式可解除问题:
1.在客户端程序前打开安全管理器:
try {
System.setSecurityManager(new java.rmi.RMISecurityManager());
mds = (IMongoDBScan) Naming.lookup(urlStr);
} catch (MalformedURLException e) {
//..........
}
2.修改/usr/java/jdk1.6.0_21/jre/lib/security/java.policy后重启
grant {
permission java.security.AllPermission;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式