大家好,小弟的RMI的SERVER和CLIENT都已经正常方法调用及通讯.但运行一段时间(十个小时左右)客户端连服务器端就会在客户端出
java.rmi.NoSuchObjectException: no such object in table
这个异常!* (目前S(rmi s端),C(RMI C端)都在本地服务器上,还没远程就有问题了) 必需要重启RMI的SERVER才可以正常运行,这个异常会影响整个平台,非常重要,我如何使它稳定呢?做过很多尝试:
如用:线程来维持 (不行),改了又改了,都没正常.
一个月了,天天要重启一次维护业务才正常,心里没谱了,才来请教达人们!
有谁遇到过呢?请指教一下
客户端代码如下:import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.net.MalformedURLException;
import java.util.Properties;/**
* Created by IntelliJ IDEA.
* User: likl
* Date: 2007-7-26
* Time: 10:12:15
* To change this template use File | Settings | File Templates.
*/
public class MobileClient
{ private String remoteHost ="127.0.0.1";
private GkbMachineIf remoteObject;
RevPackage revPackage ;
int revCount = 0;
public MobileClient(){
try{
// if(System.getSecurityManager()==null){
// System.setSecurityManager(new RMISecurityManager());
// }
int rmiServerPort = 5002;
String bindUrl = "rmi://"+remoteHost+":"+ rmiServerPort +"/MachineServer";
//String bindUrl = "MachineServer";
System.out.println("rmi : " + bindUrl );
remoteObject = (MachineIf) Naming.lookup(bindUrl);
}catch(RemoteException re){
System.out.println("RemoteException:"+re);
}catch(NotBoundException nbe){
System.out.println("NotBoundException:"+nbe);
}catch(MalformedURLException mfe){
System.out.println("MalformedURLException:"+mfe);
}
} public String testRMIString(){
String author = "test";
try{
//System.out.println("---" + remoteObject.getAuthor() );
author = remoteObject.getAuthor();
}
catch(RemoteException re){
System.out.println( " RemoteException:" + re );
}
return author;
}
public String PingMachine( String machineName ){
String msg="";
try{
msg = remoteObject.PingMachine(machineName);
}
catch(RemoteException re){
System.out.println("RemoteException:"+re);
}
System.out.println("RMI ping machine msg -->> " + msg);
return msg;
} public RevPackage getMachineStateGroup ( String machineName ){ try{
revPackage = remoteObject.getMachineGroupState( machineName ); }
catch(RemoteException re){
System.out.println("RemoteException:"+re);
}
return revPackage;
}
java.rmi.NoSuchObjectException: no such object in table
这个异常!* (目前S(rmi s端),C(RMI C端)都在本地服务器上,还没远程就有问题了) 必需要重启RMI的SERVER才可以正常运行,这个异常会影响整个平台,非常重要,我如何使它稳定呢?做过很多尝试:
如用:线程来维持 (不行),改了又改了,都没正常.
一个月了,天天要重启一次维护业务才正常,心里没谱了,才来请教达人们!
有谁遇到过呢?请指教一下
客户端代码如下:import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.net.MalformedURLException;
import java.util.Properties;/**
* Created by IntelliJ IDEA.
* User: likl
* Date: 2007-7-26
* Time: 10:12:15
* To change this template use File | Settings | File Templates.
*/
public class MobileClient
{ private String remoteHost ="127.0.0.1";
private GkbMachineIf remoteObject;
RevPackage revPackage ;
int revCount = 0;
public MobileClient(){
try{
// if(System.getSecurityManager()==null){
// System.setSecurityManager(new RMISecurityManager());
// }
int rmiServerPort = 5002;
String bindUrl = "rmi://"+remoteHost+":"+ rmiServerPort +"/MachineServer";
//String bindUrl = "MachineServer";
System.out.println("rmi : " + bindUrl );
remoteObject = (MachineIf) Naming.lookup(bindUrl);
}catch(RemoteException re){
System.out.println("RemoteException:"+re);
}catch(NotBoundException nbe){
System.out.println("NotBoundException:"+nbe);
}catch(MalformedURLException mfe){
System.out.println("MalformedURLException:"+mfe);
}
} public String testRMIString(){
String author = "test";
try{
//System.out.println("---" + remoteObject.getAuthor() );
author = remoteObject.getAuthor();
}
catch(RemoteException re){
System.out.println( " RemoteException:" + re );
}
return author;
}
public String PingMachine( String machineName ){
String msg="";
try{
msg = remoteObject.PingMachine(machineName);
}
catch(RemoteException re){
System.out.println("RemoteException:"+re);
}
System.out.println("RMI ping machine msg -->> " + msg);
return msg;
} public RevPackage getMachineStateGroup ( String machineName ){ try{
revPackage = remoteObject.getMachineGroupState( machineName ); }
catch(RemoteException re){
System.out.println("RemoteException:"+re);
}
return revPackage;
}
楼主【playboylee】截止到2008-06-27 10:43:37的历史汇总数据(不包括此帖):
发帖数:3 发帖分:60
结贴数:3 结贴分:60
未结数:0 未结分:0
结贴率:100.00% 结分率:100.00%
敬礼!
现在以上异常没用了.又出现了:RemoteException:java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: java.net.SocketTimeoutException: Read timed out 不知道兄台能否再帮一下!
C端:保持对远程接口的持久引用。远程对象检查到没有引用,在服务器端会被关闭
问题不在C端.改成static测试了两三天了,的确解决了问题,为何出现第二个异常就实在不懂了.
结贴了也要继续:
首先在服务器端的注册的远程对象数目固定的话,意味着在客户端也只能获取有限的几个注册远程接口 通过Naming.lookup在客户端使用HashMap<String,Remote>来记录已经获取的远程接口,字符串就是绑定名称(可以带HOST和端口)这样做避免了每次通过Naming来找接口,但是会带来另外一个问题:如果服务器端 对象重置(程序reset或者对象重建)后,客户端绑定的接口就没有用了,而且会出问题 Connect refused!那么问题就是 Naming.lookup和HaspMap.get相比较,哪个效率更高?