0

我有一个来自客户端的 EJB 调用,如下所示:

Portfolio[] ptfTab = ServicesMgr.getInstance().getPortfolioService().getPortfolios();

getPortfolioService() 返回 PortfolioFinderDelegate(EJB 客户端接口)的一个实例。来自客户端的 EJB 服务具有以下签名:

public interface PortfolioFinder extends IBasic {
   Portfolio[] getPortfolios();
}

对于服务器端的EJB,该方法的实现是:

public Portfolio[] getPortfolios() {
    List<Portfolio> portfolioList = getPortfoliosAsList();
    return portfolioList.toArray(new Portfolio[portfolioList.size()]);
}

getPortfolioAsList() 方法是一个私有方法:

 private List<Portfolio> getPortfoliosAsList() {
     List<Portfolio> portfolioList = new ArrayList<Portfolio>();
     LOCK.readLock().lock();
     try {
          List<String> keys = portfolioCache.getKeys();
          for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) 
              {
               String codeport = iterator.next();
               Set<Portfolio> s =(Set<Portfolio>) portfolioCache.get(codeport) .getValue();
               portfolioList.addAll(s);
              }
         } catch (Throwable e) {
                LOGGER.error(e.getMessage(), e);
         } finally {
                LOCK.readLock().unlock();
         }

         return portfolioList;
   }

昨天,我得到了一个奇怪的堆栈跟踪,我以前从未遇到过,我确信服务器端的投资组合缓存不为空。此外,服务器端没有错误日志。当第一个客户端遇到此错误时,所有客户端都有它。这个问题与返回对象的大小有关吗?(因为缓存大小每天都在增加)通过EJB对数据进行序列化和反序列化时,对象大小是否有限制?

2019-02-26 14:51:35 ERROR [StartupMgr][EJBPortfolioMgr.java:57] : Error while sending a request
javax.ejb.EJBException: Error while sending a request
                at org.ow2.easybeans.proxy.client.ClientRPCInvocationHandler.invoke(ClientRPCInvocationHandler.java:205)
                at org.ow2.easybeans.proxy.client.ClientRPCInvocationHandler.invoke(ClientRPCInvocationHandler.java:117)
                at com.sun.proxy.$Proxy33.getPortfolios(Unknown Source)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at com.clam.mediaplus.client.services.ProxyRemoteObject.invoke(ProxyRemoteObject.java:87)
                at com.sun.proxy.$Proxy33.getPortfolios(Unknown Source)
                at client.delegate.common.PortfolioFinderDelegate.getPortfolios(PortfolioFinderDelegate.java:46)
                at com.casits.rambo.dao.portfolio.EJBPortfolioMgr.reload(EJBPortfolioMgr.java:42)
                at com.casits.rambo.dao.portfolio.AbstractPortfolioMgr.<init>(AbstractPortfolioMgr.java:24)
                at com.casits.rambo.dao.portfolio.EJBPortfolioMgr.<init>(EJBPortfolioMgr.java:31)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
                at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
                at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:948)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:901)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
                at com.casits.rambo.dao.common.CommonBeanFactory.getPortfolioMgr(CommonBeanFactory.java:54)
                at com.casits.rambo.dao.portfolio.PortfolioMgr.getAttribPortfolio(PortfolioMgr.java:82)
                at com.casits.rambo.dao.portfolio.PortfolioMgr.getAttribPortfolio(PortfolioMgr.java:151)
                at com.casits.rambo.dao.portfolio.PortfolioMgr$2.processRow(PortfolioMgr.java:217)
                at org.springframework.jdbc.core.JdbcTemplate$RowCallbackHandlerResultSetExtractor.extractData(JdbcTemplate.java:1408)
              at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:445)
                at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:395)
                at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)
                at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:459)
                at com.casits.rambo.dao.portfolio.PortfolioMgr.getAllAttribPortfolios(PortfolioMgr.java:207)
                at com.casits.attrib.refptf.controller.RefPortfolioMgr.getAllAttribCodeports(RefPortfolioMgr.java:257)
                at com.casits.attrib.refptf.controller.RefPortfolioMgr.refreshAttribCodeports(RefPortfolioMgr.java:243)
                at com.casits.attrib.refptf.controller.RefPortfolioMgr.init(RefPortfolioMgr.java:221)
                at com.casits.attrib.refptf.controller.RefPortfolioMgr.<init>(RefPortfolioMgr.java:239)
                at com.casits.attrib.refptf.controller.RefPortfolioMgr.<clinit>(RefPortfolioMgr.java:191)
                at com.casits.attrib.refptf.RefPtfModule.init(RefPtfModule.java:80)
                at com.casits.attrib.attribcommon.AbstractModule.load(AbstractModule.java:70)
                at com.casits.attrib.main.MainJFrame.executeEnableModule(MainJFrame.java:418)
                at com.casits.attrib.main.MainJFrame.addModule(MainJFrame.java:336)
                at com.casits.attrib.main.MainGUI.createAndShowGUI(MainGUI.java:80)
                at com.casits.attrib.main.StartupMgr.init(StartupMgr.java:82)
                at com.casits.attrib.attribcommon.manager.AttribUserMgr$1.run(AttribUserMgr.java:390)
                at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Error while handling answer on the remote side 
                at org.ow2.easybeans.rpc.rmi.client.RMIClientRPC.sendEJBRequest(RMIClientRPC.java:116)
                at org.ow2.easybeans.proxy.client.ClientRPCInvocationHandler.invoke(ClientRPCInvocationHandler.java:202)
                ... 49 more
Caused by: java.rmi.UnmarshalException: IOException unmarshalling returnjava.io.OptionalDataException; nested exception is: 
                java.io.OptionalDataException
                at org.ow2.carol.rmi.jrmp.server.JUnicastRef.performRemoteCall(JUnicastRef.java:212)
                at org.ow2.carol.rmi.jrmp.server.JUnicastRef.invoke(JUnicastRef.java:161)
                at org.ow2.easybeans.rpc.rmi.server.RMIServerRPCImpl_Stub.getEJBResponse(RMIServerRPCImpl_Stub.java:60)
                at org.ow2.easybeans.rpc.rmi.client.RMIClientRPC.sendEJBRequest(RMIClientRPC.java:114)
                ... 50 more
Caused by: java.io.OptionalDataException
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1370)
                at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
                at java.util.HashMap.readObject(HashMap.java:1179)
                at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
                at java.util.HashMap.readObject(HashMap.java:1180)
                at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
                at java.util.HashMap.readObject(HashMap.java:1180)
                at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
                at java.util.HashMap.readObject(HashMap.java:1180)
                at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
                at java.util.HashMap.readObject(HashMap.java:1180)
                at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1706)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1344)
                at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
                at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
                at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
                at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
                at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
                at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:325)
                at org.ow2.carol.rmi.jrmp.server.JUnicastRef.performRemoteCall(JUnicastRef.java:205)
                ... 53 more
4

1 回答 1

0

简而言之,在我们的应用程序代码中,一个复杂的值对象(用作远程方法调用的返回值)具有一个 HashMap 数据结构作为内部字段。将此字段的类型更改为 ConcurrentHashMap 后,OptionalDataExceptions 停止发生。似乎在遗留代码的某个地方,这个 Map 是以非线程安全的方式处理的。

于 2019-07-11T09:17:42.937 回答