com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1035079 -- APPARENT DEADLOCK!!! Complete Status: Managed Threads: 3 Active Threads: 3 Active Tasks: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@b1cc87 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@eaf40c (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@13c6641 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) Pending Tasks: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5d391d com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@50a649 Pool thread stack traces: Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main] java.net.PlainSocketImpl.socketConnect(Native Method) java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) java.net.Socket.connect(Socket.java:529) java.net.Socket.connect(Socket.java:478) java.net.Socket.<init>(Socket.java:375) java.net.Socket.<init>(Socket.java:218) com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253) com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280) com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026) com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718) com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) java.lang.reflect.Constructor.newInstance(Constructor.java:513) com.mysql.jdbc.Util.handleNewInstance(Util.java:406) com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302) com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282) com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137) com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014) com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810) com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main] java.net.PlainSocketImpl.socketConnect(Native Method) java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) java.net.Socket.connect(Socket.java:529) java.net.Socket.connect(Socket.java:478) java.net.Socket.<init>(Socket.java:375) java.net.Socket.<init>(Socket.java:218) com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253) com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280) com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026) com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718) com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) java.lang.reflect.Constructor.newInstance(Constructor.java:513) com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
关于这个错误最开始也是莫名其妙,原因是我自己写的一个jar包在本机上运行是十分正常的,但是当我把这个jar文件提供给项目组的另一个同事使用时,则报出了这个错误,后来自己也在网上搜索了关于出现这个错误的原因,发现出现这种错误的原因有很多,现在总结如下:
1.数据库服务没有启动
以上出现的错误就是我在关闭了自己机器上的mysqld后亲测的一个错误,我的机器上的mysql服务器是默认开启的,但是由于将jar包给同时后,他的机器上其实是没有mysql的,所以会出现错误
2.没有创建对应数据库
在mysqld开启的情况下,没有对应数据库的情况下也是会出现这样的问题的
3.就涉及到c3p0连接池的配置文件了
由于我遇到的不是这个问题,所以只能在网上参照一些配置方面出问题的原因,关于配置出错的问题众说纷纭,具体以自己的项目出错为准
①maxStatements 和checkoutTimeout
原因:I'm surprised that no other theories or options have come out... Is there really no way to deal with the cached statement warnings other than to completely disable prepared statement caching? If so, that reduces the value of c3p0 to connection pool only.
这段话我是从hibernate论坛中截取出来的,大致意思就是c3p0在同时关闭statment和connection的同时,由于他们关闭的时间有一个很短的间隔,但是在这个时间段内,connection并没有被关闭,导致了有一些perparedstatment还处于缓存当中
另外,从我参考的文章来看,他是在做压力测试时1小时候才出现的问题,所以如果本身上来说的话,没有一次性做大量的连接数据库的操作的话,应该是不会出现这样的问题的
②maxPoolSize和initialPoolSize
在这篇文章中,他把值都设置成了1,给出的解释是:
因为数据库的连接数是有限的,每次应用启动C3p0都会占用数据库的连接来填充C3p0的连接池,而当数据库的资源被占光时就会因为无法获得共享资源而报死锁。仅仅摘录,遇到问题的童鞋们不妨试一试
③更新c3p0的包
有可能是c3p0的包版本过旧造成的,版本低的c3p0包会导致获取连接的时间过长而在获取新的连接时造成死锁,具体参考的是*中别人提出的一个问题
The tasks that are dealocking are Connection acquisition tasks. That is, c3p0 is trying to acquire new Connections from your database, and those Connection acquisition attempts are taking a long time. The first thing I would do is upgrade to 0.9.2.1, which has a much improved means of performing a round of Connection acquisitions in situations where acquisition attempts sometimes fail. If that doesn't solve your problem, then you'll need to figure out why c3p0's attempts to acquire a Connection are hanging for long periods of time: neither succeeding nor failing with an Exception. |
参考文章:
http://colbybobo.iteye.com/blog/1754435
http://blog.sina.com.cn/s/blog_776860890100rxc0.html
http://blog.csdn.net/truong/article/details/9492405
https://forum.hibernate.org/viewtopic.php?t=947246&highlight=apparent+deadlock+c3p0
http://*.com/questions/18100414/c3p0-apparent-deadlock-exception