C3P0连接池错误

Ibatis中关于C3p0连接池的配置如下:

xml 代码
  1. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
  2.         <property name="driverClass" value="${jdbc.driverClassName}"/>  
  3.         <property name="jdbcUrl" value="${jdbc.url}"/>  
  4.         <property name="user" value="${jdbc.username}"/>  
  5.         <property name="password" value="${jdbc.password}"/>  
  6.            
  7.     <property name="minPoolSize" value="1"/>  
  8.         <property name="maxPoolSize" value="20"/>  
  9.         <property name="maxIdleTime" value="10"/>  
  10.         <property name="acquireIncrement" value="3"/>  
  11.         <property name="maxStatements" value="0"/>  
  12.         <property name="initialPoolSize" value="20"/>  
  13.         <property name="idleConnectionTestPeriod" value="10"/>  
  14. </bean>  

在执行的时候报如下错误信息:

WARN - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1eeb95
e -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending task
s!
WARN - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1eeb95
e -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@d43997
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@110f85
0 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@11e8d5
c (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@d2ad3c

Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5
,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(Ba
sicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5
,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(Ba
sicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5
,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(Ba
sicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java:547)

解决办法:

更改配置文件里的最大连接数和初始化连接数大小:

xml 代码
  1. <property name="maxPoolSize" value="1"/>  
  2. <property name="initialPoolSize" value="1"/>  

因为数据库的连接数是有限的,每次应用启动C3p0都会占用数据库的连接来填充C3p0的连接池,而当数据库的资源被占光时就会因为无法获得共享资源而报死锁。

你可能感兴趣的:(java,thread,bean,ibatis,jdbc)