请注意..这个问题在经过大量的EJP时间之后已经被清理干净了。 (真诚道歉并深深感谢帮助延长。)
我们有一个客户端 - 服务器应用程序。沟通是RMI。我们在应用程序中只获得了以下异常。该计划已经运行了5年多,但下面提到的例外最近才发生过一次。
例外是
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.company.server.TestImplConcrete
at com.company.server.TopicSessionImpl_Stub.createPublisher(Unknown Source)
at com.company.process.finance.client.transactionservers.clientClass$TailorCalcManager.calc(clientClass.java:92)
at com.company.process.finance.client.transactionservers.clientClass$TailorCalcManager.access$500(clientClass.java:37)
at com.company.process.finance.client.transactionservers.clientClass.processTransaction(clientClass.java:346)
at com.company.process.finance.TransactionServer.processTransaction(TransactionServer.java:50)
at com.company.products.server.TransactionalProductManager.processTransaction(TransactionalProductManager.java:120)
at com.company.products.server.TransactionalProductManager.processTransaction(TransactionalProductManager.java:110)
at com.company.process.core.Manager$BrokerListener.readITMsg(Manager.java:74)
at com.company.core.util5.FixedSizeThreadPoolMsgBus$ParallelTask.run(FixedSizeThreadPoolMsgBus.java:37)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.company.server.TestImplConcrete
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 12 more
Caused by: java.io.NotSerializableException: com.company.server.TestImplConcrete
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at com.company.server.TopicSessionImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
... 1 more
我已经阅读了一些帖子,他们建议将 TestImplConcrete 类作为序列化来逃避异常。我完全认为 TestImplConcrete 类是 NOT 序列化。但这里的问题是,如果这是解决问题的唯一方法,那么这个班级过去5年是如何考虑的?班级如何仍然没有任何问题?
注意:我们只有一次这个问题然后,重新启动过程后,一切正常。 另请注意,问题与我的代码无关,它与序列化和RMI有关。
代码在这里:
// The colling class
Class CallingClass {
Public void createSubscription (){
TopicImpl topicPublisher = null;
try {
TopicImpl sessionInter = (TopicImpl) Naming.lookup(url);
if (sessionInter != null) {
topicPublisher = sessionInter.createMap();
}
} catch (Exception e) {
Logger.error(e);
}
}
}
The colling interface
public interface TopicImpl extends Remote {
TestImpl createMap() throws RemoteException ;
}
// Concrete class for calling interface
public class TopicImplConcrete implements TopicImpl {
String name = "abc";
// this map is give some value during class initialization
private ConcurrentHashMap<String, TestImplConcrete> concHashMap = new ConcurrentHashMap<String, TestImplConcrete>();
public TopicPublisher createMap() {
TestImpl refOfHere = getMethodHere(name);
return refOfHere;
}
public TestImplConcrete getMethodHere(String name) {
if (name != null) {
TestImplConcrete ref = concHashMap.get(name);
if (ref != null)
return ref;
synchronized (this) {
ref = concHashMap.get(name);
if (ref != null)
return ref;
ref = new TestImplConcrete(name);
concHashMap.put(name, ref);
try {
if (!ref.isExported()) {
UnicastRemoteObject.exportObject(ref);
ref.setExported(true);
}
} catch (RemoteException e) {
log.error("Remote Exception", e);
}
}
return ref;
}
return null;
}
}
// The interface being sent over..
public interface TestImpl extends Remote {
public TestImpl getMethod1() throws RemoteException;
public void method2() throws RemoteException;
}
// concrete class for the interface being sent over.
public class TestImplConcrete implements TestImpl {
private boolean isExportedBoolean;
public boolean isExported() {
return isExportedBoolean;
}
public void setExported(boolean isExportedBoolean) {
this.isExportedBoolean = isExportedBoolean;
}
public TestImpl getMethod1() {
// do something
}
public void method2() {
// do something
}
}
请注意:代码已经过编辑,只提供相关信息。如果需要更多信息,请告诉我。上面粘贴的相同代码已经好几年了。但有一次它显示 NotSerializableException 。
答案 0 :(得分:0)
testImpl
不需要是Serializable,但如果不是,则需要在传递或通过RMI返回时导出。