We recently switched from commons dbcp to tomcat dbcp and after 2-3 weeks another architect ran into an issue where his backend job would run into a resultset close issue. He was saying it started right about the time we made the switch and it happens only for long running jobs. That reminds me of something I had read about abandoned connections so I asked him to check after how many minutes it does this and it was 20min 1 sec. It seems I had added a property in dbcp
dataSource.setLogAbandoned(true);
dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(1200);
so first thing was to confirm if this was really the case because our transaction timeout for long running queries is also 20 min but that has been for ages so this abandoned was the only recent change. Finally I found logAbandoned would log into tomcat catalina.out and I indeed saw this
Jun 18, 2014 3:54:07 PM org.apache.tomcat.jdbc.pool.ConnectionPool abandon
WARNING: Connection has been abandoned PooledConnection[com.mysql.jdbc.JDBC4Connection@2ba0c302]:java.lang.Exception
at org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:1062)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:779)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:615)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:187)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
So now only thing left is to fix it.
There are two approaches:
dataSource.setLogAbandoned(true);
dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(1200);
so first thing was to confirm if this was really the case because our transaction timeout for long running queries is also 20 min but that has been for ages so this abandoned was the only recent change. Finally I found logAbandoned would log into tomcat catalina.out and I indeed saw this
Jun 18, 2014 3:54:07 PM org.apache.tomcat.jdbc.pool.ConnectionPool abandon
WARNING: Connection has been abandoned PooledConnection[com.mysql.jdbc.JDBC4Connection@2ba0c302]:java.lang.Exception
at org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:1062)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:779)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:615)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:187)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
So now only thing left is to fix it.
There are two approaches:
- While iterarting resultset reset the abandoned timer for long running job using ResetAbandonedTimer
- Or for now just use dataSource.setAbandonWhenPercentageFull(50);
Comments
Post a Comment