文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

mysql hikari连接池异常处理(com.zaxxer.hikari.pool.ProxyConnection)

2023-09-02 21:32

关注

异常信息如下:com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 603,312 milliseconds ago. 

### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 603,312 milliseconds ago. The last packet sent successfully to the server was 603,312 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.### The error may exist in com/dbappsecurity/base/mapper/SysConfigMapper.java (best guess)### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL: DELETE FROM tb_sys_config     WHERE (code = ?)### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 603,312 milliseconds ago. The last packet sent successfully to the server was 603,312 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.; The last packet successfully received from the server was 603,312 milliseconds ago. The last packet sent successfully to the server was 603,312 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.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 603,312 milliseconds ago. The last packet sent successfully to the server was 603,312 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.2023-03-29 11:00:57 | [89-exec-10] ERROR c.d.base.config.security.BaseExceptionHandler : Catch Exception,message=JDBC commit failed; nested exception is java.sql.SQLException: Connection is closedorg.springframework.transaction.TransactionSystemException: JDBC commit failed; nested exception is java.sql.SQLException: Connection is closed

问题提示的原因:

  1. sql的问题
  2. 让我们设置数据路连接超时时间
  3. 设置数据库的超时时间参数

实际定位下来,都不是,因为这sql之前执行过;

解决过程如下(数据库命令可以在Navicat执行,也可以直接在服务器上执行):

show variables like '%max_connection%'; -- 查看数据库设置的链接数,默认最大是1000,

show global status like 'Thread%'; -- 查看当前数据库已经连的数量,并且各连状态

综合1和2,得出实际连接是不超标,理论上能够获取到数据库连接的;

继续定位

show PROCESSLIST; -- 查询数据库中哪些线程正在执行,执行状态是什么,如果存在lock时,执行的内容是什么

-- 此时显示,在调用数据库操作时,存在等待锁的情况。truncate tb_sys_schudual_record 是 lock状态

-- 这导致该事物里面其他的sql操作被阻塞。

为什么是lock状态?

-- 代码流程存在问题,在执行truncate tb_sys_schudual_record 之前,方法里对该表进行了其他操作。由于该方法被事务所管理,并且该方法还未执行完,事务不会被提交,此时在去truncate该表,就会被锁住。

-- 最终导致该错误的出现。

总结:

代码问题:操作同一张表时,应该注意表锁的问题

来源地址:https://blog.csdn.net/m0_55476995/article/details/129839711

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯