简体   繁体   中英

Tomcat7 JDBC abandoned PooledConnection

Our setup : Hibernate4, JPA, Oracle11g, OJDBC6 version 11.2.0.2.0 [same as our Oracle DB version].

Our context bean:

<Resource name="jdbc/DataSource"
        type="javax.sql.DataSource"
        auth="Container"
        username=""
        password=""
        driverClassName="oracle.jdbc.OracleDriver"
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        url="jdbc:oracle:thin:@ip:1521:sid"
        maxActive="50"
        maxIdle="10"
        minIdle="5"
        suspectTimeout="60"
        timeBetweenEvictionRunsMillis="30000"
        minEvictableIdleTimeMillis="60000"
        removeAbandonedTimeout="60"
        removeAbandoned="true"
        logAbandoned="true"
        testOnBorrow="true"
        testWhileIdle="true"
        testOnReturn="false"
        validationQuery="SELECT 1 FROM DUAL"
        validationInterval="30000"
        jmxEnabled="false"
        jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"
        connectionProperties="v$session.program=dev-cs"/>

Trying to run fairly simple update & insert, curreny 121 rows each, will occassionally be as big as 8000 rows each.

for (int i = 0; i < bUpdated.size(); i++) {
   entityManager.merge(bUpdated.get(i));
   entityManager.persist(pInserted.get(i));
   if(i % 50 == 0) {
      entityManager.flush();
   }
}
entityManager.flush();

I've been trying different spins on our connection settings, removing the abandoned timeout, etc and looked through the jar.

With showSql=true, we see that the large number of selects we do before the update & inserts work fine, but a connection abandoned error is thrown after the first flush [you can see the singular insert into the database].

Edit: Sorry, should have included stacktrace :

WARNING: Connection has been abandoned PooledConnection[oracle.jdbc.driver.T4CConnection@1359bbfb]:java.lang.Exception
            at org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:1063)
            at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:780)
            at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:619)
            at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
            at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
            at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
            at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
            at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
            at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
            at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
            at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
            at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1395)
            at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:59)

It was solved, it turns out certain members of the team were not commiting their changes made in SQL Developer, so there was a lock in the table that the insert was failing on. I wonder if there is a way of better logging that would have made the issue clearer.

But thanks for any reads of my question :-).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM