7
回答
JFinal有关c3p0数据库连接池配置问题
注册华为云得mate10,2.9折抢先购!>>>   

@JFinal

请教您一个问题,这是我的一个报错:

APPARENT DEADLOCK!!! Complete Status: 
Managed Threads: 3
Active Threads: 3
Active Tasks: 
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15873881 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@608ea831 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@35c45a7d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
Pending Tasks: 
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6e10e01e
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15ea0a06
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@38381b27
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6b7eba46
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4cf780cc
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@d28f88e
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7cd63961
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.net.PlainSocketImpl.socketConnect(Native Method)
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
java.net.Socket.connect(Socket.java:519)
java.net.Socket.connect(Socket.java:469)
java.net.Socket.<init>(Socket.java:366)
java.net.Socket.<init>(Socket.java:209)
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2391)
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2428)
com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2213)
com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)
com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
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:333)
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
java.net.Socket.connect(Socket.java:519)
java.net.Socket.connect(Socket.java:469)
java.net.Socket.<init>(Socket.java:366)
java.net.Socket.<init>(Socket.java:209)
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2391)
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2428)
com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2213)
com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)
com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
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-#0,5,main]
java.net.PlainSocketImpl.socketConnect(Native Method)
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
java.net.Socket.connect(Socket.java:519)
java.net.Socket.connect(Socket.java:469)
java.net.Socket.<init>(Socket.java:366)
java.net.Socket.<init>(Socket.java:209)
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2391)
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2428)
com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2213)
com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)
com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
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)


 
[EMMM] 2013-12-16 16:15:11,741 - com.mchange.v2.async.ThreadPoolAsynchronousRunner -80140 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - Task com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15873881 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[EMMM] 2013-12-16 16:15:11,741 - com.mchange.v2.async.ThreadPoolAsynchronousRunner -80140 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - Task com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@608ea831 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[EMMM] 2013-12-16 16:15:11,741 - com.mchange.v2.async.ThreadPoolAsynchronousRunner -80140 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - Task com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@35c45a7d (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[EMMM] 2013-12-16 16:15:18,868 - com.mchange.v2.resourcepool.BasicResourcePool -87267 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] WARN  com.mchange.v2.resourcepool.BasicResourcePool  - com.mchange.v2.resourcepool.BasicResourcePool@1b14deda -- Thread unexpectedly interrupted while performing an acquisition attempt. 
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
[EMMM] 2013-12-16 16:15:18,868 - com.mchange.v2.resourcepool.BasicResourcePool -87267 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] WARN  com.mchange.v2.resourcepool.BasicResourcePool  - com.mchange.v2.resourcepool.BasicResourcePool@1b14deda -- Thread unexpectedly interrupted while performing an acquisition attempt. 
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
[EMMM] 2013-12-16 16:15:18,877 - com.mchange.v2.resourcepool.BasicResourcePool -87276 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] WARN  com.mchange.v2.resourcepool.BasicResourcePool  - com.mchange.v2.resourcepool.BasicResourcePool@1b14deda -- Thread unexpectedly interrupted while performing an acquisition attempt. 
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


估计是c3p0没有正常关闭数据源导致的死锁情况,我去网上查过这个是c3p0本来就有的一个bug,解决方法是将maxStatement设为0,因为JFinal是零配置,我不知道哪里可以修改这个参数,并且我在C3p0Plugin这个类里边没有发现有关这个参数的设置,DataSource类里边也没发现有,请问该如何配置此参数?

举报
wang_liran
发帖于4年前 7回/4K+阅
共有7个答案 最后回答: 2年前

    检查一下程序中有无 DbKit.getConnection() 这样的代码,是否在 finally 中关闭了 connection。

    另外 JFinal 虽然零配置,但也是支持配置的,详见 jfinal_demo 项目中的配置。 C3P0Plugin 是可以配置相关参数的,可以在 new 出 C3P0Plugin对象后,看一下属于它的setXxxx 方法

--- 共有 2 条评论 ---
JFinal回复 @wang_liran : 在 YourJFinalConfig.afterJFinalStart()中这样来:DbKit.getDataSource().setMaxStatements(...) 4年前 回复
wang_liranC3p0plugin对象中没发现maxStatement参数设置的方法,怎么破? 4年前 回复

引用来自“JFinal”的评论

引用来自“wang_liran”的答案

引用来自“JFinal”的答案

    检查一下程序中有无 DbKit.getConnection() 这样的代码,是否在 finally 中关闭了 connection。

    另外 JFinal 虽然零配置,但也是支持配置的,详见 jfinal_demo 项目中的配置。 C3P0Plugin 是可以配置相关参数的,可以在 new 出 C3P0Plugin对象后,看一下属于它的setXxxx 方法

找不到此方法,难道我导错包?没理由啊,我是用demo里边的包的 

这个方法是 c3p0的 com.mchange.v2.c3p0.ComboPooledDataSource 才有的方法,需要先强制转换一下:

((com.mchange.v2.c3p0.ComboPooledDataSource)DbKit.getDataSource()).setXxxx(...);

最新的JFinal是不是没有

getDataSource()

这个方法了,DbKit下没有了

--- 共有 1 条评论 ---
JFinaljfinal 1.5 以后的版本,由于支持了多数源,所以引入了 Config,所以上述的操作也就变成了 DbKit.getConfig().getDataSource() 2年前 回复

引用来自“JFinal”的答案

    检查一下程序中有无 DbKit.getConnection() 这样的代码,是否在 finally 中关闭了 connection。

    另外 JFinal 虽然零配置,但也是支持配置的,详见 jfinal_demo 项目中的配置。 C3P0Plugin 是可以配置相关参数的,可以在 new 出 C3P0Plugin对象后,看一下属于它的setXxxx 方法

求指教,急

引用来自“JFinal”的答案

    检查一下程序中有无 DbKit.getConnection() 这样的代码,是否在 finally 中关闭了 connection。

    另外 JFinal 虽然零配置,但也是支持配置的,详见 jfinal_demo 项目中的配置。 C3P0Plugin 是可以配置相关参数的,可以在 new 出 C3P0Plugin对象后,看一下属于它的setXxxx 方法

找不到此方法,难道我导错包?没理由啊,我是用demo里边的包的 

引用来自“wang_liran”的答案

引用来自“JFinal”的答案

    检查一下程序中有无 DbKit.getConnection() 这样的代码,是否在 finally 中关闭了 connection。

    另外 JFinal 虽然零配置,但也是支持配置的,详见 jfinal_demo 项目中的配置。 C3P0Plugin 是可以配置相关参数的,可以在 new 出 C3P0Plugin对象后,看一下属于它的setXxxx 方法

找不到此方法,难道我导错包?没理由啊,我是用demo里边的包的 

这个方法是 c3p0的 com.mchange.v2.c3p0.ComboPooledDataSource 才有的方法,需要先强制转换一下:

((com.mchange.v2.c3p0.ComboPooledDataSource)DbKit.getDataSource()).setXxxx(...);
顶部