如果在Proxy EJB容器中工作,则对象不会关闭\返回到池中的连接

时间:2016-06-03 08:25:53

标签: java ejb weblogic

我基于weblogic应用服务器的集成解决方案。 (Oracle零售集成总线)。解决方案的每个适配器都是EJB组件。 Weblogic Console Application view

有两种类型的适配器,第一种用于XA事务,第二种用于NONXA事务。 (在PLSQL API函数中使用外部过程程序时需要NONXA。)

  1. XA - OracleObjectSubscriberComponentImpl

            public class OracleObjectSubscriberComponentImpl
          extends DefaultAdaptorComponentImpl
          implements SubscriberComponent
        {
          ....
          protected void performSubscribe(RibContext ribContext, RibMessage inRibMessage, RibMessages outRibMsg)
            throws RibAPIException
          {
            boolean success = false;
    
            Connection connection = null;
            try
            {
              setRibContext(ribContext);
              setRibMessagesOut(outRibMsg);
              connection = getNewConnection();
              initCallableStatement(connection, null);
              registerOutParams();
              if (setInParams(inRibMessage))
              {
                execute();
                processResult();
                success = true;
              }
            }
            finally
            {
              end(success);
              cleanup();
    
              super.closeConnection(connection);
            }
          }
    
          public void performSubscribe(RibContext ribContext, RibMessage inRibMessage)
            throws RibAPIException
          {
            performSubscribe(ribContext, inRibMessage, null);
          }
    
          public void subscribe(RibContext ribContext, RibMessage inRibMessage)
            throws RibAPIException
          {
            performSubscribe(ribContext, inRibMessage);
          }
          ...
        }
    
  2. NonXA - OracleObjectSubscriberComponentNonXAImpl扩展了OracleObjectSubscriberComponentImpl。

    public class OracleObjectSubscriberComponentNonXAImpl
          extends OracleObjectSubscriberComponentImpl
        {
          public void initCallableStatement(Connection c, String msgType)
            throws RibAPIException
          {
            try
            {
              c.setAutoCommit(false);
            }
            catch (SQLException e)
            {
              this.LOG.error("Could not turn off AutoCommit", e);
              throw createRibAPIException("initStmt", e);
            }
            super.initCallableStatement(c, msgType);
          }
    
          public void end(boolean successful)
          {
            super.end(successful);
            try
            {
              if (successful) {
                this.conn.commit();
              } else {
                this.conn.rollback();
              }
              this.conn.setAutoCommit(true);
            }
                    catch (SQLException sqle)
            {
              String errorString = "Error occurred during commit/rollback";
              this.LOG.error(errorString, sqle);
              throw new RuntimeException(errorString, sqle);
            }
          }
    
          public void subscribe(RibContext ribContext, RibMessage inRibMessage)
            throws RibAPIException
          {
            NonTransactionalSubscriberCoreService nonTransactionalSubscriberCoreService =         (NonTransactionalSubscriberCoreService)RetailServiceFactory.getService(NonTransactionalSubscriberCoreService.class);
    
           nonTransactionalSubscriberCoreService.subscribe(this, ribContext, inRibMessage);
          }
        }
    
  3. 它们之间的区别是:

    1. NonXA Autocommit = false,this.conn.commit();和this.conn.rollback();用来代替XA Autocommit = true。
    2. NonXA得到了覆盖方法订阅,其中创建了新的代理服务,NonXA对象进入了Proxy,它将执行Perform Subscribe。
    3. 非XA类使用NonTransactionalSubscriberCoreServiceEjb类,这是一个代理服务:

          public class NonTransactionalSubscriberCoreServiceEjb
            implements NonTransactionalSubscriberCoreService, SessionBean
          {
            ...
          public void subscribe(OracleObjectSubscriberComponentNonXAImpl subscriber, RibContext ribContext, RibMessage inRibMessage)
              throws RibAPIException
            {
              RibContextFactory.setCurrentRibContext(ribContext);
              subscriber.performSubscribe(ribContext, inRibMessage);
              RibContextFactory.clearCurrentRibContext();
            }
            ...
          }
      

      所有适配器都不并行,每个适配器从JMS主题逐个获取消息。 XA组件工作正常,它在weblogic数据源中获得连接,并在工作完成后返回。 NonXA没有按预期工作,它从数据中获取连接而不释放它,连接保持到超时为止。

      如果我更改NonXA类,请订阅此方法:

            public void subscribe(RibContext ribContext, RibMessage inRibMessage)
              throws RibAPIException
            {
                this.performSubscribe(ribContext, inRibMessage);
            }
      

      连接将在工作完成后发布,但我不能在API中使用External Proc,因为引发了ORA-xxx(XA中不支持此功能)。我需要保留NonXA功能并释放连接。

1 个答案:

答案 0 :(得分:0)

解决方案:

  1. 如果从weblogic服务器管理数据源。 从Weblogic控制台获取数据源,
  2. 取消选中"在本地交易后保持连接" 检查"删除已启用的受感染连接"

    1. 如果从appliaction管理数据源,请在datasource xml文件中进行相同的更改。 <jdbc-data-source> <name>rib-rms-managed-datasource</name> <jdbc-driver-params> <url>jdbc:oracle:thin:@monrmsdb.apm.local:1521:retekdb</url> <driver-name>oracle.jdbc.xa.client.OracleXADataSource</driver-name> <properties> <property> <name>user</name> <value>RMS13DEV</value> </property> </properties> </jdbc-driver-params> <jdbc-connection-pool-params> <initial-capacity>0</initial-capacity> <max-capacity>350</max-capacity> <capacity-increment>10</capacity-increment> <connection-creation-retry-frequency-seconds>1</connection-creation-retry-frequency-seconds> <test-connections-on-reserve>false</test-connections-on-reserve> <profile-harvest-frequency-seconds>60000</profile-harvest-frequency-seconds> <inactive-connection-timeout-seconds>5</inactive-connection-timeout-seconds> <statement-cache-size>0</statement-cache-size> <!-- Add this--><remove-infected-connections>true</remove-infected-connections> <pinned-to-thread>false</pinned-to-thread> </jdbc-connection-pool-params> <jdbc-data-source-params> <jndi-name>jdbc/OracleRibDs</jndi-name> <global-transactions-protocol>TwoPhaseCommit</global-transactions-protocol> <!-- Add this--><keep-conn-after-local-tx>false</keep-conn-after-local-tx> </jdbc-data-source-params> </jdbc-data-source>