月丨曦 2021-03-29 10:39 采纳率: 0%
浏览 434
已结题

使用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" />

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

  • 写回答

3条回答 默认 最新

  • thomas.he 2021-03-29 10:42
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程