小工具知识网

当前位置: 首页 > 行业知识 > Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: Hika

行业知识

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

2026-12-05 01:12:34 来源:互联网转载

一、报错日志

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 里面自动会关闭

上一篇:微代驾源码深度解析,技术奥秘大揭秘

下一篇:ai服务器怎么出租的?