java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Springboot项目长时间不进行接口操作,提示HikariPool-1

Springboot项目长时间不进行接口操作,提示HikariPool-1警告的解决

作者:程序猿不秃头

这篇文章主要介绍了Springboot项目长时间不进行接口操作,提示HikariPool-1警告的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

问题描述

Spring boot项目长时间未进行操作,前端进行调用接口时第一次会报警报,并且接口访问时间过长而导致第一次调用接口失败

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@286d93a8] was not registered for synchronization because synchronization is not active
2020-12-01 11:27:56.356  WARN 8392 --- [nio-9099-exec-7] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@17b7bbbb (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-12-01 11:28:01.359  WARN 8392 --- [nio-9099-exec-7] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@43a8ad76 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-12-01 11:28:06.362  WARN 8392 --- [nio-9099-exec-7] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@11ef23d4 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-12-01 11:28:11.366  WARN 8392 --- [nio-9099-exec-7] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@4cb8a9c2 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-12-01 11:28:16.373  WARN 8392 --- [nio-9099-exec-7] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@22641536 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-12-01 11:28:21.375  WARN 8392 --- [nio-9099-exec-7] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@3946dfc7 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

解决方法

我们查看数据库的HikariPool源码

找到HikariDataSource类,他继承了HikariConfig

我们看Hikar的相关配置,进入HikarConfig中,在这里我们可以看到默认池大小为10,我们在数据库配置中修改默认池大小即可解决问题

配置文件中加入

    hikari:
      minimum-idle: 3
      maximum-pool-size: 5
      max-lifetime: 0

修改过配置文件后即可解决问题

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文