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,我们在数据库配置中修改默认池大小即可解决问题
配置文件中加入
- minimum-idle最小空闲数
- maximum-pool-size链接池最大数量
- max-lifetime最大时长,配置为0则是永久不过期
hikari: minimum-idle: 3 maximum-pool-size: 5 max-lifetime: 0
修改过配置文件后即可解决问题
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
SpringBoot源码分析之bootstrap.properties文件加载的原理
本文通过访问看到bootstrap.properties中的信息获取到了,同时age也被application.properties中的属性覆盖掉了。加载顺序到底是什么?为什么会覆盖呢?我们接下来分析下吧2021-12-12
最新评论