admin 管理员组文章数量: 1086019
问题背景:
我用的springboot2.2.,Hikari,,mysql,mp-plus。没有用druid,我不需要监控,就用spring自带的,做数据库连接时候,有段时间不连接,过一会就出错:
HikariPool-1 - Failed to validate connection com.mysql.jdbc.JDBC*********** (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
***问题尝试解决:***他说的是:Possibly consider using a shorter maxLifetime value.
翻译:可以考虑使用更短的maxLifetime值。
然后我又查了https://github/brettwooldridge/HikariCP
官方解释:maxLifetime
This property controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed will it then be removed. On a connection-by-connection basis, minor negative attenuation is applied to avoid mass-extinction in the pool. We strongly recommend setting this value, and it should be several seconds shorter than any database or infrastructure imposed connection time limit. A value of 0 indicates no maximum lifetime (infinite lifetime), subject of course to the idleTimeout setting. Default: 1800000 (30 minutes)
翻译:
maxLifetime
此属性控制池中连接的最大生存期。正在使用的连接永远不会退役,只有当它关闭时才会被移除。在逐个连接的基础上,应用了较小的负衰减来避免池中的大规模消光。***我们强烈建议设置此值,它应该比任何数据库或基础设施设置的连接时间限制短几秒。***值0表示没有最大生存期(无限生存期),当然,这取决于idleTimeout设置。默认值:1 800 000(30分钟)
我的操作:
我最开始是没有任何设置的,然后设置了10 000 也就是10秒,她说最低就要300 000,不然就是默认30分钟,我就设置了30 000可以,60 000可以 80 000不可以,120 000不行,120 000+都不行。
问题貌似是解决了。
官方解释是和我的MYSQL设置有关,但是我查了我的MYSQL:
这个表默认单位是秒,找了很多资料 说是wait_timeout,28800也就是8个小时,我真是日了狗了,Hikaril默认都是30分钟,怎么可能超过8小时?,难道是connect_timeout?10秒,貌似也不是吧?
解决的答案是蒙的,没有什么依据。
路过的大神说说呢?
2020-04-30 00:39:40.706 WARN 21284 --- [nio-9128-exec-6] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@40beab48 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2020-04-30 00:39:40.714 ERROR 21284 --- [nio-9128-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30019ms.
### The error may exist in ***************Mapper.java (best guess)
### The error may involve**********************Mapper.selectByMap
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30019ms.] with root cause
com.mysql.cj.exceptions.ConnectionIsClosedException: No operations allowed after connection closed.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
本文标签: Possibly Hikaril maxLifetime shorter
版权声明:本文标题:Hikaril过一段时间就出错,Possibly consider using a shorter maxLifetime value问题 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1738335344a1965739.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论