1)起因:使用了一个rmi服务,奇怪的是,同一个RMI服务器export的多个远程对象有的能访问,有的不能,而且还不一定能,即:有的时候能,有的时候不能。异常如下:
java.rmi.NoSuchObjectException: no such object in table
java.rmi.NoSuchObjectException: no such object in table
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at com.domain.Monitor_Stub.accept(Unknown Source)
at
com.domain.Scheduler.Server.jobs.VerifyFailedMonitorsJob.execute(VerifyFailedMonitorsJob.java:60)
at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
the code to perform lookup and then some operations looks like
this:
2)分析:经过分析,发现由于在远程服务器export远程对象的时候是匿名对象的方式:
IRemoteObject obj =
(IAppContextServiceRemote)UnicastRemoteObject.exportObject(new
RemoteObj(),0);
registry.rebind("myRemoteServcie", obj);
关键点在于:匿名对象创建后,没有其他的引用,导致方法返回后,可能会被system
GC(即JAVA的垃圾回收),所以出现了可能可不能的现象。
3)解决方法:创建static静态变量,对RemoteObj进行引用。这样即使方法返回,也不会没有对此对象的引用。
此异常非常飘忽不定,很难分析,幸亏有GOOGLE啊。呵呵。