dbcp 连接池不合理的锁导致连接耗尽解决方案
网络编程 2021-07-05 11:23www.168986.cn编程入门
这篇文章主要介绍了dbcp 连接池不合理的锁导致连接耗尽解决方案的相关资料,需要的朋友可以参考下
dbcp 连接池不合理的锁导致连接耗尽解决方案
应用报错,表象来看是连接池爆满了。
.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is .apache.mons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted at .springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:241) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE] at .alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82) [dubbo-2.5.3.jar:2.5.3] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_33] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_33] at java.lang.Thread.run(Thread.java:662) [na:1.6.0_33] Caused by: .apache.mons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted at .apache.mons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:103) ~[mons-dbcp.jar:1.2.1] at .apache.mons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) ~[mons-dbcp.jar:1.2.1] at .eshore.crmpub.jdbc.datasource.MultiDataSource.getConnection(MultiDataSource.java:74) ~[crmpub-jdbc-1.0.jar:1.0] at .springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:203) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE] ... 32 mon frames omitted Caused by: java.util.NoSuchElementException: Timeout waiting for idle object at .apache.mons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1174) ~[mons-pool-1.6.jar:1.6] at .apache.mons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:74) ~[mons-dbcp.jar:1.2.1] at .apache.mons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95) ~[mons-dbcp.jar:1.2.1] ... 35 mon frames omitted
应用堆栈,几十条线程都阻塞到dbcp池的PoolableConnectionFactory.makeObject方法了,此方法在等待0x0000000709a638a0对象锁,但0x0000000709a638a0对象一直被其中一条线程执行PoolableConnectionFactory.makeObject时锁了,而且这条线程获取到锁后还阻塞住了,所以导致后面几十条线程都BLOCKED了。
"DubboServerHandler-132.121.95.136:28101-thread-300" daemon prio=10 tid=0x00007f02b4136800 nid=0x4954 waiting for monitor entry [0x00007f0286018000] java.lang.Thread.State: BLOCKED (on object monitor) at .apache.mons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290) - waiting to lock <0x0000000709a638a0> (a .apache.mons.dbcp.PoolableConnectionFactory) at .apache.mons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188) at .apache.mons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:74) at .apache.mons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95) at .apache.mons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) at .eshore.crmpub.jdbc.datasource.MultiDataSource.getConnection(MultiDataSource.java:74) at .springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:203) at .springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372) at .springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417) at .springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255) at .springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at .springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80) at .eshore.crm.service.mon.pub.aspect.DataSourceRouteAspect.around(DataSourceRouteAspect.java:74) at sun.reflect.GeneratedMethodAessor253.invoke(Unknown Source) at sun.reflect.DelegatingMethodAessorImpl.invoke(DelegatingMethodAessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at .springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at .springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at .springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at .springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at .springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) at .eshore.crm.service.sysmgr.sca.impl.SysMgrServiceImpl$$EnhancerByCGLIB$$bfd71326.qryBulletinList(<generated>) at .alibaba.dubbo.mon.bytecode.Wrapper101.invokeMethod(Wrapper101.java) at .alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46) at .alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72) at .alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53) at .eshore.crmpub.sca.dubbo.filter.BaseFilter.invoke(BaseFilter.java:90) at .alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at .alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108) at .alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84) at .alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170) at .alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52) at .alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Locked ownable synchronizers: - <0x000000070a120f00> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
"DubboServerHandler-132.121.95.136:28101-thread-290" daemon prio=10 tid=0x00007f03203da800 nid=0x4948 runnable [0x00007f0286a22000] java.lang.Thread.State: RUNNABLE at java..SocketInputStream.socketRead0(Native Method) at java..SocketInputStream.read(SocketInputStream.java:129) at .mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:112) at .mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:159) at .mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:187) - locked <0x0000000715a9ce70> (a .mysql.jdbc.util.ReadAheadInputStream) at .mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3140) at .mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:597) at .mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1085) at .mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2494) at .mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527) at .mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309) - locked <0x00000007159d1898> (a .mysql.jdbc.JDBC4Connection) at .mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) at .mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) at sun.reflect.GeneratedConstructorAessor78.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAessorImpl.newInstance(DelegatingConstructorAessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at .mysql.jdbc.Util.handleNewInstance(Util.java:408) at .mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:419) at .mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344) at .apache.mons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37) at .apache.mons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290) - locked <0x0000000709a638a0> (a .apache.mons.dbcp.PoolableConnectionFactory) at .apache.mons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188) at .apache.mons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:74) at .apache.mons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95) at .apache.mons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) at .eshore.crmpub.jdbc.datasource.MultiDataSource.getConnection(MultiDataSource.java:74) at .springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:203) at .springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372) at .springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417) at .springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255) at .springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at .springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80) at .eshore.crm.service.mon.pub.aspect.DataSourceRouteAspect.around(DataSourceRouteAspect.java:74) at sun.reflect.GeneratedMethodAessor253.invoke(Unknown Source) at sun.reflect.DelegatingMethodAessorImpl.invoke(DelegatingMethodAessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at .springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at .springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at .springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at .springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at .springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) at .eshore.crm.service.cachemgr.sca.mon.DictCacheServiceImpl$$EnhancerByCGLIB$$e27e8e25.getDict(<generated>) at .alibaba.dubbo.mon.bytecode.Wrapper93.invokeMethod(Wrapper93.java) at .alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46) at .alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72) at .alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53) at .eshore.crmpub.sca.dubbo.filter.BaseFilter.invoke(BaseFilter.java:90) at .alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at .alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108) at .alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84) at .alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170) at .alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52) at .alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Locked ownable synchronizers: - <0x000000070a0f9218> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
可以看到其实获取锁的线程是阻塞在这里了,做mysql握手包的时候一直在等待读,阻塞在网络IO了。
java.lang.Thread.State: RUNNABLE at java..SocketInputStream.socketRead0(Native Method) at java..SocketInputStream.read(SocketInputStream.java:129) at .mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:112) at .mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:159) at .mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:187) - locked <0x0000000715a9ce70> (a .mysql.jdbc.util.ReadAheadInputStream) at .mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3140) at .mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:597) at .mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1085) at .mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2494) at .mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527) at .mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309)
这个是dbcp1.x版本在创建新的连接对象时会把整个连接工厂类对象锁了,一旦创建过程中发生阻塞就会导致整个池都死掉。这个问题很大。
解决方案,升级dbcp2.x版本或tomcat jdbc或druid连接池,推荐druid连接池,功能强大自带监控。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程