问题描述:运行一个多线程程序,在一两小时不用的情况下,再执行mybatis的sql会报错。重启应用后正常,但也不是个事情。
错误日志如下:
2020-02-13 04:22:22.395 [HikariPool-1 housekeeper] WARN com.zaxxer.hikari.pool.HikariPool -
HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=30m53s308ms122µs99ns).
2020-02-13 04:25:28.566 [AsyncResolver-bootstrap-executor-0] INFO c.n.d.shared.resolver.aws.ConfigClusterResolver -
Resolving eureka endpoints via configuration
2020-02-13 04:30:28.569 [AsyncResolver-bootstrap-executor-0] INFO c.n.d.shared.resolver.aws.ConfigClusterResolver -
Resolving eureka endpoints via configuration
2020-02-13 04:30:52.716 [SchedulerFactory_Worker-4] ERROR com.task.job.HttpJob -
taskExpiredDao.updateFireTime(448,df-msgcenter-core)失败,原因:nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating 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 925628ms.
### 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 925628ms.
2020-02-13 04:30:52.718 [SchedulerFactory_Worker-4] ERROR com.wanmei.df.task.job.HttpJob -
日志大概意思分析到为:
HikariPool WARN 连接泄露,然后Error连接超时,应该是使用了无效的连接没有释放或出现错误,导致客户端再次获取时候连接不可用。
检查:
1、数据库连接是否配置正确
2、数据库连接池配置问题
3、网络问题
解决:
1、我的网络没问题,那么就修改完善数据库连接池配置,添加空闲连接超时释放和最大存活时间,目的是保证连接池资源。
aximum-pool-size: 10 connection-timeout: 30000 idle-timeout: 60000 max-lifetime: 120000
单位毫秒,注意:idel+timeout的时间+1s 不能超过max-lifetime的时间,否则会置零,导致配置失效。
2、但是我配置完连接池参数还是出错,仔细查看日志,原来是配置的驱动名出错。
原来的:driver-class-name: oracle.jdbc.driver.OracleDriver
新的,正确的:driver-class-name: oracle.jdbc.OracleDriver
在1,2都修改完成后,测试观察,已经一天没有出现错误了