遇到的问题之“动态数据源报错-recyle error java.lang.InterruptedException”
Druid出现DruidDataSource - recyle error - recyle error java.lang.InterruptedException: null异常排查与解决
一、线上的代码之前运行的都很平稳,突然就出现了一个很奇怪的问题,看错误信息是第三方框架Druid报出来了,连接池回收连接时出现的问题。
[][ERROR][2024-07-01 11:00:57] com.alibaba.druid.pool.DruidDataSource.recycle 1448 | recyle error java.lang.InterruptedException at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1220) at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335) at com.alibaba.druid.pool.DruidDataSource.recycle(DruidDataSource.java:1425) at com.alibaba.druid.pool.DruidPooledConnection.recycle(DruidPooledConnection.java:320) at com.alibaba.druid.filter.FilterChainImpl.dataSource_recycle(FilterChainImpl.java:4534) at com.alibaba.druid.filter.FilterAdapter.dataSource_releaseConnection(FilterAdapter.java:2717) at com.alibaba.druid.filter.FilterChainImpl.dataSource_recycle(FilterChainImpl.java:4530) at com.alibaba.druid.pool.DruidPooledConnection.close(DruidPooledConnection.java:263) at org.springframework.jdbc.datasource.DataSourceUtils.doCloseConnection(DataSourceUtils.java:348) at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:335) at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:302) at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion(DataSourceTransactionManager.java:370) at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1021) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:815) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:734) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:293) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) at com.sun.proxy.$Proxy1351.syncTransaction(Unknown Source) at com.bessky.financial.hander.WfTransactionJobHandler.execute(WfTransactionJobHandler.java:31) at com.xxl.job.core.thread.JobThread.run(JobThread.java:152)
二、排查问题
查看一下他的源码
看了一下也没有发现所以然,然后去GitHub上的Druid官方开源处,看了一下历史问题修复,发现这个是旧版本已知的一个Bug。
https://github.com/alibaba/druid/issues/785
看了一下当前使用的Druid的版本【1.0.29】,然后又确认了一下官方版本是【1.1.9】,已经差了很多个版本了。
果断将版本更新至【1.1.9】
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.9</version> </dependency>
翻看之前出错的那里的代码发现
更新到最新版本后,上述问题得到解决。
数据库连接被中断的原因有很多,有一种是初始化配置时设置的数据库连接回收时长,通过datasource.getConnontion() 取得的连接必须在removeAbandonedTimeout这么多秒内调用close(),否则就主动将其杀死,就是conn不能超过指定的租期。
详细配置可以参考这篇文章:
https://my.oschina.net/haogrgr/blog/224010
原文链接:https://blog.csdn.net/lingyejun/article/details/121647149
* 博客文章部分截图及内容来自于学习的书本及相应培训课程,仅做学习讨论之用,不做商业用途。
* 如有侵权,马上联系我,我立马删除对应链接。
* 备注:王子威
* 我的网易邮箱:wzw_1314_520@163.com