Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: Hika

一、报错日志

2024-03-26 10:32:07,356 ERROR [http-nio-8080-exec-43] cn.com.AA.util.
LogHelper [LogHelper.java : 24] Failed to obtain JDBC Connection; 
nested exception is java.sql.SQLTransientConnectionException: 
HikariPool-1 - Connection is not available, request timed out after 126290ms.

二、配置

spring boot + hikari。启动一段时间就会报错,无奈隔一段时间重启一下,隔一段时间重启一下

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: root
    hikari:
      minimum-idle: 5
      maximum-pool-size: 24
      connection-timeout: 60000
      # connection-test-query: select 1
      idle-timeout: 50000
      max-lifetime: 54000
 

各种查询,网上都是这种配置,但是问题依旧在。tmd

三、排查

第一步:看哪个SQL占着链接

拿到id一条SQL一条SQL执行(3个SQL)

show processlist;
# 查询链接

select * from performance_schema.threads t  where PROCESSLIST_ID = 78955
# 查看进程

select * from performance_schema.events_statements_current esc  where THREAD_ID = 91618
# 查看正在执行的SQL

 第二步:查询代码

使用idea的快捷命令全局搜索   Ctrl + Shift + R    在搜索框输入上面查询到的SQL语句

第三步: 修改代码关闭链接 

jdk 8的特性一些资源放到try 里面自动会关闭

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值