Home » MySQL » Using the timeout recovery mechanism of the Druid ...

Using the timeout recovery mechanism of the Druid connection pool, troubleshoot connection leaks


The Druid connection pool was used in the project. After running for some time, the system has an exception:







  1. Causedby:org.springframework.jdbc.CannotGetJdbcConnectionException:CouldnotgetJDBCConnection; nestedexceptioniscom.alibaba.druid.pool.GetConnectionTimeoutException:waitmillis60009, active50

  2. Atorg.springframework.jdbc.datasource.DataSourceUtils.getConnection (DataSourceUtils.java:80)

  3. Atorg.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData (JdbcUtils.java:280)

  4. ... 64more

  5. Causedby:com.alibaba.druid.pool.GetConnectionTimeoutException:waitmillis60000, active50

  6. Atcom.alibaba.druid.pool.DruidDataSource.getConnectionInternal (DruidDataSource.java:1071)

  7. Atcom.alibaba.druid.pool.DruidDataSource.getConnectionDirect (DruidDataSource.java:898)

  8. Atcom.alibaba.druid.filter.FilterChainImpl.dataSource_connect (FilterChainImpl.java:4544)





The maximum number of connections in the MySQL database is set to 500, using the client to connect normally. The number of connections is not accounted for by.







The reason for the analysis is that there is a local connection in your program that has not been closed. How do you decide? Use the timeout recovery mechanism for the Druid connection pool to add the following in your configuration:







  1. recovery
    <propertyname=, removeAbandoned, value= true, />

  2. =3 minutes.180 seconds
    <propertyname=, removeAbandonedTimeout, value=, 180, />

  3. -->
  4. <propertyname=, logAbandoned, value= true, />





Run the program, when the connection is more than 3 minutes, will be forced to recycle, and output abnormal log.









  1. 2014-10-1316:02:28919ERROR[com.alibaba.druid.pool.DruidDataSource]-<abandonconnection, openstackTrace

  2. Atjava.lang.Thread.getStackTrace (Thread.java:1567)

  3. Atcom.alibaba.druid.pool.DruidDataSource.getConnectionDirect (DruidDataSource.java:995)

  4. Atcom.alibaba.druid.filter.FilterChainImpl.dataSource_connect (FilterChainImpl.java:4544)

  5. Atcom.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection (StatFilter.java:661)

  6. Atcom.alibaba.druid.filter.FilterChainImpl.dataSource_connect (FilterChainImpl.java:4540)

  7. Atcom.alibaba.druid.pool.DruidDataSource.getConnection (DruidDataSource.java:919)

  8. Atcom.alibaba.druid.pool.DruidDataSource.getConnection (DruidDataSource.java:911)

  9. Atcom.alibaba.druid.pool.DruidDataSource.getConnection (DruidDataSource.java:98)


  10. Atcn.org.xxx.xxx.xxx.PaginationInterceptor.intercept (PaginationInterceptor.java:96)


  11. Atorg.apache.ibatis.plugin.Plugin.invoke (Plugin.java:60)

  12. Atcom.sun.proxy.$Proxy59.query (UnknownSource)

  13. Atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList (DefaultSqlSession.java:108)







It is clear where the open connection is not closed and has been in possession of.







This configuration item affects performance and opens only during troubleshooting. It is best to turn off.

when the system is running




Latest