C3P0错误APPARENT DEADLOCK!!!解决

阅读更多

文章转自 http://japi.iteye.com/blog/243702

Java代码   收藏代码
  1. [framework] 2008-09-18 18:36:05,109 - com.mchange.v2.async.ThreadPoolAsynchronousRunner -46651078 [Timer-18] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1c17bd4 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!  



网上说是连接池的原因.... 

我的C3P0配置 

Java代码   收藏代码
  1.   
  2.         org.hibernate.connection.C3P0ConnectionProvider  
  3.       
  4.     20  
  5.     200  
  6.     1800  
  7.     100  
  8.     true  



对于以上错误,查阅了类似问题网友的解答: 
一:http://www.iteye.com/topic/22160?page=3 

引用
把max_statements设置为0。 
c3p0在同时关闭statement和connection的时候,或者关闭他们之间的时间很短的时候,有时候connection并没有被关闭,因为有些preparedstatement还在被cached住。这是c3p0的作者自己说的。 
http://forum.hibernate.org/viewtopic.php?t=947246&highlight=apparent+deadlock+c3p0 


对于这个解答,看下我的设置: 

Java代码   收藏代码
  1. 100  


因为这里c3p0.max_statements写错了,所以设置无效,看下日志 

Java代码   收藏代码
  1. [framework] 2008-09-18 06:32:48,906 - com.mchange.v2.c3p0.C3P0Registry -3257219 [TP-Processor1] INFO  com.mchange.v2.c3p0.C3P0Registry  - Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]  
  2.  [framework] 2008-09-18 06:32:48,906 - com.mchange.v2.c3p0.management.ActiveManagementCoordinator -3257219 [TP-Processor1] WARN  com.mchange.v2.c3p0.management.ActiveManagementCoordinator  - A C3P0Registry mbean is already registered. This probably means that an application using c3p0 was undeployed, but not all PooledDataSources were closed prior to undeployment. This may lead to resource leaks over time. Please take care to close all PooledDataSources.  
  3.  [framework] 2008-09-18 06:32:49,015 - com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource -3257328 [TP-Processor1] INFO  com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource  - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@7111383 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@a9b46d3 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2rysjs7wvr5h721dikp1v|1880048, idleConnectionTestPeriod -> 0, initialPoolSize -> 20, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 200, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 20, nestedDataSource ->   


maxStatements的默认值为0 
所以这种解决方法,感觉不行 

二.http://yonguo.iteye.com/blog/120574 

引用
更改配置文件里的最大连接数和初始化连接数大小: 
Xml代码   收藏代码
  1.      
  2.     


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


此方法可能有理,但没有测试. 

三.http://www.iteye.com/problems/1082 

引用
Basic Pool Configuration  
c3p0 Connection pools are very easy to configure via the following basic parameters: 

acquireIncrement 
initialPoolSize 
maxPoolSize 
maxIdleTime 
minPoolSize 
initialPoolSize, minPoolSize, maxPoolSize define the number of Connections that will be pooled. Please ensure that minPoolSize <= maxPoolSize. Unreasonable values of initialPoolSize will be ignored, and minPoolSize will be used instead. 

Within the range between minPoolSize and maxPoolSize, the number of Connections in a pool varies according to usage patterns. The number of Connections increases whenever a Connection is requested by a user, no Connections are available, and the pool has not yet reached maxPoolSize in the number of Connections managed. Since Connection acquisition is very slow, it is almost always useful to increase the number of Connections eagerly, in batches, rather than forcing each client to wait for a new Connection to provoke a single acquisition when the load is increasing. acquireIncrement determines how many Connections a c3p0 pool will attempt to acquire when the pool has run out of Connections. (Regardless of acquireIncrement, the pool will never allow maxPoolSize to be exceeded.) 

The number of Connections in a pool decreases whenever a pool tests a Connection and finds it to be broken (see Configuring Connection Testing below), or when a Connection is expired by the pool after sitting idle for a period of time, or for being too old (See Managing Pool Size and Connection Age.)




四.http://blog.sina.com.cn/s/blog_3e7ed9500100abzz.html 

根据以上的一些解答,修改配置文件: 

Xml代码   收藏代码
  1.   
  2.             org.hibernate.connection.C3P0ConnectionProvider  
  3.           
  4.   
  5.                   1  
  6.         1  
  7.         500  
  8.                     
  9.         1800  
  10.      
  11.     1000   
  12.         true  
  13. 3   



对于这种配置也不知道结果会怎么样? 
不知道有没有什么测试方法能马上看到效果? 

其实hibernate里支持的c3p0参数没有多少.更多的还得在c3p0.property文件中定义 
http://www.mchange.com/projects/c3p0/index.html#c3p0_properties 

你可能感兴趣的:(C3P0错误APPARENT DEADLOCK!!!解决)