使用mysql 连接池 GetConnectionTimeoutException

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC 
Connection for transaction; nested exception is 
com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 30000, active 12, 
runningSqlCount 1 : 

1.最近经常遇到这个问题,重启之后会缓和,但是过了一天就又出现了。

2.查了CSDN一些大佬的推荐是

2.1.wait timeout 设置值过高,从 8H修改为60S之后,出现了新的问题 

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 83,820 milliseconds ago. The last packet sent successfully to the server was 83,822 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 

2.2 代码中未释放连接,使用的连接池,查看了每次代码连接,均有释放连接,并未查到释放连接的报错

2.3 设置 泄露的 配置 removeAbandoned 和 removeAbandonedTimeout  查看均有配置 

	
		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="${db.maxwait}" />
		
		<!-- 超过时间限制是否回收 -->  
		<property name="removeAbandoned" value="true" />  
		
		<!-- 超时时间;单位为秒。180秒=3分钟   -->
		<property name="removeAbandonedTimeout" value="1800" />  
		
		<!-- 关闭abanded连接时输出错误日志   -->
		<property name="logAbandoned" value="false" />  
		
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="10000" />
		
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="30000" />
		
		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

以上均看过,都 无发现问题,求大佬帮忙看看

个人还和连接池没有关系,你测试下网络是不是正常的,感觉是获取数据库连接掉包了,拿不到连接就出问题了,

首先看异常信息,在获取连接的抛出了异常,但是又没有等待很久(说明应该不是连接数量问题),那么估计是网络环境问题。建议监控一下网络环境。是只要到了过了一天,就会频繁抛出这个异常,还是只在某一个时间点才会出现。

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully 
received from the server was 83,820 milliseconds ago. The last packet sent successfully to 
the server was 83,822 milliseconds ago. is longer than the server configured value of 
'wait_timeout'. You should consider either expiring and/or testing connection validity 
before use in your application, increasing the server configured values for client 
timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this 
problem. 

经过修改 wait timeou = 60S 以后,有新的问题 ,参考h

ttps://blog.csdn.net/lzwglory/article/details/78752563

但是这位大佬没有写清楚具体jdbc需要修改的配置是哪些,我只修改了 

mysql 修改wait timeou = 60S  系统jdbcmaxWait 默认为 30S

是否以下还有修改的呢?

<property name="maxWait" value="30000" />

<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> 

<property name="timeBetweenEvictionRunsMillis" value="10000" /> 

<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->

<property name="minEvictableIdleTimeMillis" value="30000" />