系統症狀:java
某個功能報錯:spring
可是數據庫連接並無用完。重啓一下tomcat就行了,可是過十幾分鍾又報錯,如此反覆。數據庫
懷疑是數據庫鏈接泄露。因而加入下面的配置進行調查:tomcat
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> ...... <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="180" /> <property name="logAbandoned" value="true" /> </bean>
查到報錯信息:ui
[ERROR] com.alibaba.druid.pool.DruidDataSource.removeAbandoned(DruidDataSource.java:2664):Druid-ConnectionPool-Destroy-1730184957 - abandon connection, owner thread: http-apr-8181-exec-186, connected at : 1560136511767, open stackTrace
at java.lang.Thread.getStackTrace(Thread.java:1559)
at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1311)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1233)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1223)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:90)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:246)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:461)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.xxxx.controller.FileController.getxxxxjrxx(FileController.java:382)spa
......線程
ownerThread current state is BLOCKED, current stackTrace
at java.lang.Throwable.printStackTrace(Throwable.java:655)
at java.lang.Throwable.printStackTrace(Throwable.java:643)
at java.lang.Throwable.printStackTrace(Throwable.java:634)
at com.xxx.service.xxxServiceImpl.getxxx(Btjc01ServiceImpl.java:544)
at com.xxx.service.xxxServiceImpl$$FastClassBySpringCGLIB$$5df1f982.invoke(<generated>)
code
最後查到是線程被某個外部接口給 BLOCKED,致使其持有的數據庫鏈接沒法釋放,從而致使數據庫鏈接泄露,從而致使該問題。orm
其實就是 數據庫鏈接 的 onwerThread 被 blocked了。blog