Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60009, active 50 at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:280) ... 64 more Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 50 at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1071) at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:898) at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
The maximum connection number of mysql database is set to 500, and the client can connect normally. The number of connections is not full.
The reason for the analysis should be that there is a place in the program where the connection is not closed. So how do you decide? Using the timeout recovery mechanism of the druid connection pool, add the following to the configuration:
<! - Is it recycled beyond the time limit? <property name="removeAbandoned" value="true" /> <! - Overtime time; in seconds. 180 seconds = 3 minutes - > <property name="removeAbandonedTimeout" value="180" /> <! - Output error log when abanded connection is closed. This configuration item affects performance and only opens when checking. It's better to shut down when the system is running. > <property name="logAbandoned" value="true" />
Running the program, when the connection exceeds 3 minutes, it will be forced to recycle and output the exception log.
2014-10-13 16:02:28,919 ERROR [com.alibaba.druid.pool.DruidDataSource] - <abandon connection, open stackTrace at java.lang.Thread.getStackTrace(Thread.java:1567) at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:995) at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544) at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661) at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:919) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:911) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:98) at cn.org.xxx.xxx.xxx.PaginationInterceptor.intercept(PaginationInterceptor.java:96) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60) at com.sun.proxy.$Proxy59.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
It's clear where the open connection is not closed has been in possession.
This configuration item can affect performance and only opens when checking. It's better to shut down when the system is running.