JDBC connection leak on JDBC pool when using AQ

不想你离开。 提交于 2019-12-11 12:20:41

问题


We are using the Oracle AQ support from spring-data to have both JMS and JDBC over the same datasource, with local transactions instead of XA. The big picture of our setup is basically what is described in the reference manual:on the orcl:aq-jms-connection-factory: use-local-data-source-transaction="true" and native-jdbc-extractor="oracleNativeJdbcExtractor" HibernateTransactionManager (I am trying to use single DataSource(DBCP2 basic datasource) now for AQ and Hibernate).I am using camel JMS component (by using hibernate transaction manager and connection factory from spring) for JMS operations. Everything is working, but after a couple of minutes we get indications that the JDBC connection pool was exhausted and everything got stuck. In the JDBC connection pool monitor, we could see that all connections where in use: so something was clearly leaking connections. exhausted pool after some minutes. Same post is here: https://jira.spring.io/browse/DATAJDBC-8

We are using:
DBCP2 Basic datasource,
Hibernate 4,
Spring 4 Hibernate Transaction Manager,
Spring Data Oracle Aq,
JBOSS 6 EAP container.

 <orcl:aq-jms-connection-factory id="connectionFactory"
        use-local-data-source-transaction="true"
        native-jdbc-extractor="dbcpNativeJdbcExtractor" 1
        data-source="dataSource" />

    <bean id="dbcpNativeJdbcExtractor" 
        class="org.springframework.jdbc.support.nativejdbc. OracleJdbc4NativeJdbcExtractor"/>

    <bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource" 
            destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

<bean id="txManager"  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="transacted" value="true"/>
        <property name="transactionManager" ref="txManager"/>
    </bean>

Any ideas? Thank you.

回答1:


We had the same problem with DBCP in Tomcat 8. The reason is that the data source by default does not allow access to the underlying native connection. The code that does the native connection extraction doesn't actually fail, but continues to return a wrapped connection not a native oracle connection. This native connection is wrapped in a proxy for passing close back to wrapped connection. When the Oracle AQ code tries to call oracle specific methods on the connection this proxy fails, and AQ aborts but leaks the connection. The fix is to allow access to the native connection by using accessToUnderlyingConnection=true in your DBCP configuration.



来源:https://stackoverflow.com/questions/36239392/jdbc-connection-leak-on-jdbc-pool-when-using-aq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!