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

article/2025/9/26 3:11:45

异常信息如下: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 closed
org.springframework.transaction.TransactionSystemException: JDBC commit failed; nested exception is java.sql.SQLException: Connection is closed

问题提示的原因:

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

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

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

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

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

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

继续定位

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

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

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

4:为什么是lock状态?

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

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

总结:

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


http://chatgpt.dhexx.cn/article/pgUrl7rp.shtml

相关文章

Hikari连接泄露分析:Apparent connection leak detected

Hikari连接池故障 前两天生产环境上触发了触发了CPU飙升的预警短信,查看日志发现出现如下数据库连接池的报错,通过网上查阅资料发现HikariCP连接泄露时就会抛出此异常。 故障分析 Hikari的相关配置 leak-detection-threshold:用来设置连接…

springboot实现多数据源配置(Druid/Hikari)

使用springbootmybatis-plus(Druid/Hikari)实现多数据源配置 操作步骤: 引入相应的maven坐标编写mybatis配置,集成mybatis或mybatis-plus(如果已集成可跳过)编写数据源配置类编写注解,并通过a…

HikariDataSource

DataSourceConfiguration 配置类,springBoot默认采用HikariDataSource /*** Hikari DataSource configuration.*/Configuration(proxyBeanMethods false)ConditionalOnClass(HikariDataSource.class)ConditionalOnMissingBean(DataSource.class)ConditionalOnPro…

Hikari

HikariCP 1 简介 数据库连接池就是在程序初始化的时候,预先创建一定数量的数据库连接对象,当后续需要数据库连接的时候,如果此时有连接未被使用,那么他就可以直接使用已经创建好的连接,不需要再重新创建新的连接&…

关于Hikari连接池的源码理解与配置使用

关于Hikari连接池的源码理解与配置使用 1. 连接池初始化 1.1 初始化连接池 对于应用者来说,我们构造一个线程池就是构造一个HikariDataSource。 重点看一下获取连接以及相关连接管理的流程。 public Connection getConnection() throws SQLException {if (this…

Hikari 讲解

前言 现在已经有很多公司在使用HikariCP了,HikariCP还成为了SpringBoot默认的连接池,伴随着SpringBoot和微服务,HikariCP 必将迎来广泛的普及。 下面带大家从源码角度分析一下HikariCP为什么能够被Spring Boot 青睐,文章目录如下…

SpringBoot系列十八:整合Hikari

Hikari是一款非常强大,高效,并且号称“史上最快连接池”。并且在springboot2.0之后,采用的默认数据库连接池就是Hikari。不需要引入依赖,已经在SpringBoot中包含了。  GitHub地址:https://github.com/brettwooldridge…

Android开发之RelativeLayout

文章目录 常见属性根据父容器定位根据兄弟容器定位 实例根据父容器定位根据兄弟组件定位 通用属性设置组件与父容器的边距设置父容器与组件的边距 常见属性 根据父容器定位 layout_alignParentStart 左对齐 layout_alignParentEnd 右对齐 layout_alignParentTop 顶部对齐 lay…

Android RelativeLayout布局

1. RelativeLayout类 相对布局(RelativeLayout)将子视图以相对位置显示。默认显示在父视图的左上角。 layout_alignParentTop,父视图的上边layout_alignParentBottom,父视图的下边layout_alignParentLeft,父视图的左…

android 继承relativelayout,Android开发中RelativeLayout相对布局

Android开发中RelativeLayout相对布局 RelativeLayout布局是Android界面布局中应用最广也最强大的一种布局,其不只十分灵活,能够解决开发中各类界面布局需求,同时也很方便了解决了多屏幕尺寸的适配问题。在iOS开发中,Autolayout技…

RelativeLayout实现居中偏下x距离引发的小问题

UE想实现一个简单的效果,某个控件在屏幕水平线下方50dp。由于受限于项目历史布局(RelativeLayout)和一套动态化设置控件位置的方案,竟然遇到了一点问题。(在这里还是喊一声:ConstraintLayout最香&#xff0…

RelativeLayout布局

RelativeLayout布局是相对布局,如果RelativeLayout中再包含两个RelativeLayout,不会像LinearLayout一样,宽高一样的话会重叠在一起 将红色布局放到右上角 常见属性 根据父容器定位 layout_alignParentLeft 左对齐 layout_alignParentRig…

RelativeLayout圆角处理

RelativeLayout圆角处理以后,可以变相对子view进行圆角处理,如ImageView,VideoView等 RoundRelativeLayout具体实现 比较简单,只需要在初始化时设置一下layout的ViewOutlineProvider,方便起见,这里写死rad…

RelativeLayout(相对布局)的基本使用

RelativeLayout又称作相对布局,也是一种非常常用的布局。和LinearLayout的排列规则不同,RelativeLayout显得更加随意一些,它可以通过相对定位的方式让控件出现在布局的任何位置。也正因为如此,RelativeLayout中的属性非常多&#…

RelativeLayout相对布局详解

RelativeLayout相对布局在Android UI开发中也应用比较多,虽然它不及LinearLayout使用方便,但某些场景中使用RelativeLayout也是一种很不错的选择。在官网上介绍RelativeLayout是一个视图组,在相对位置显示子视图。RelativeLayout是用于设计用…

Android相对布局(RelativeLayout)

Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念。 RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定)。每个视图的位置能够指定它相对于兄弟(比如在其他视图的左边或是下边)或是父视图(这里是指相对布局容…

【Android】相对布局(RelativeLayout)最全解析

【Android】相对布局(RelativeLayout)最全解析 一、相对布局(RelativeLayout)概述二、根据父容器定位三、根据兄弟控件定位 一、相对布局(RelativeLayout)概述 相对布局(RelativeLayout&#x…

Flutter ListView详解

ListView详解 ListView常用构造ListViewListView 默认构建效果 ListView ListTileListTile 属性ListTile 使用效果 ListView builderbuilder属性详细介绍分析几个比较难理解的属性效果builder模式来设置分割线 ListView separatedseparatorBuilderseparated设置分割线效果 List…

UE4 ListView

UE4-ListView UE4ListView和U3D的思路不太一样,详细了解之后发现UE4的ListView还是蛮先进的,直接就实现了逻辑和显示分离,提高效率,相对的,他的用法也比Unity的ListView绕一些。举例,一个ListView如果设置…

Android 控件 —— ListView

ListView 的简单用法 在布局中加入 ListView 控件还算简单&#xff0c;先为 ListView 指定一个 id&#xff0c;然后将宽度和高度都设置为 match_parent&#xff0c;这样 ListView 就占满了整个布局的空间 <LinearLayout xmlns:android"http://schemas.android.com/ap…