`

APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks

阅读更多

 

最近orcale数据只有一台可以服务,导致hibernate 连接数据库每个13分钟就会报“APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks”的错误.
原因是 hibernate 使用c3p0连接orcale数据后不会释放 , c3p0的最大连接数为100,但显然c3p0有Bug,导致数据库连接池不够用,导致进程锁死。
后换Proxool后,观察正常。

下面转引其它网友文章说明C3p0 、 Proxool、 Dbcp  的区别

1<!-- JDBC驱动程序 -->   
2<property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/struts?useUnicode=true&characterEncoding=GBK</property> <!-- 数据库用户名 -->   
3<property name="connection.username">root</property> <!-- 数据库密码 -->

上面的一段配置,在c3p0和dbcp 中,都是必需的,因为hibernate会根据上述的配置来生成connections,再交给c3p0或dbcp管理。

1 c3p0

只需在hibernate.cfg.xml中加入 

1<property name="c3p0.min_size">5</property>   
2<property name="c3p0.max_size">30</property>   
3<property name="c3p0.time_out">1800</property>   
4<property name="c3p0.max_statement">50</property>   
5

还有在classespath中加入c3p0-0.8.4.5.jar 

 

2 dbcp 
在hibernate.cfg.xml中加入 

 1<property name="dbcp.maxActive">100</property>   
 2<property name="dbcp.whenExhaustedAction">1</property>   
 3<property name="dbcp.maxWait">60000</property>   
 4<property name="dbcp.maxIdle">10</property>   
 5   
 6<property name="dbcp.ps.maxActive">100</property>   
 7<property name="dbcp.ps.whenExhaustedAction">1</property>   
 8<property name="dbcp.ps.maxWait">60000</property>   
 9<property name="dbcp.ps.maxIdle">10</property>  
10

还有在classespath中加入commons-pool-1.2.jar 和commons-dbcp-1.2.1.jar. 

3 proxool 
由于数据库connection在较长时间没有访问下会自动断开连接,导致浏览出错,增加proxool作为数据库pool。它有自动连接功能。
1)、从
http://proxool.sourceforge...下载proxool,释放proxool.jar到WEB-INF/lib

2)、在hibernate.cfg.xml中增加:

1<property name="hibernate.proxool.pool_alias">dbpool</property>   
2<property name="hibernate.proxool.xml">proxool.xml</property>   
3<property name="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>  
4


3)、在与hibernate.cfg.xml同级目录(src根目录下)增加proxool.xml文件:

 1<?xml version="1.0" encoding="utf-8"?>   
 2<!-- the proxool configuration can be embedded within your own application's.    
 3 Anything outside the "proxool" tag is ignored. -->   
 4<something-else-entirely>   
 5 <proxool>   
 6   <alias>dbpool</alias>   
 7   <!--proxool只能管理由自己产生的连接-->   
 8   <driver-url>   
 9     jdbc:mysql://127.0.0.1:3306/wlsh?characterEncoding=GBK&useUnicode=true&autoReconnect=true     </driver-url>   
10   <driver-class>com.mysql.jdbc.Driver</driver-class>   
11   <driver-properties>   
12       <property name="user" value="root" />   
13       <property name="password" value="123456" />   
14   </driver-properties>   
15   <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->   
16   <house-keeping-sleep-time>90000</house-keeping-sleep-time>   
17   <!-- 最少保持的空闲连接数-->   
18   <prototype-count>5</prototype-count>   
19   <!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->   
20   <maximum-connection-count>100</maximum-connection-count>   
21   <!-- 最小连接数-->   
22   <minimum-connection-count>10</minimum-connection-count>   
23 </proxool>   
24</something-else-entirely>  
25


于在hibernate3.0中,已经不再支持dbcp了,hibernate的作者在hibernate.org中,明确指出在实践中发现dbcp有 BUG,在某些种情会产生很多空连接不能释放,所以抛弃了对dbcp的支持。至于c3p0,有评论说它的算法不是最优的,因为网上查资料得知:有网友做了一个实验,在同一项目中分别用了几个常用的连接池,然后测试其性能,发现c3p0占用资源比较大,效率也不高。所以,基于上述原因,proxool不少行家推荐使用,而且暂时来说,是负面评价是最少的一个。在三星中也有项目是用proxool的。从性能和出错率来说,proxool稍微比前两种好些。C3P0,稳定性似乎不错,在这方面似乎有很好的口碑。至于性能,应该不是最好的,算是中规中矩的类型。 
  Proxool的口碑似乎很好,不大见到负面的评价,从官方资料上来看,有许多有用的特性和特点,也是许多人推荐的。

 

 

转载:

http://blog.csdn.net/chinesesword/article/details/7902702

 

分享到:
评论

相关推荐

    C3P0错误APPARENT DEADLOCK 解决根本问题

    网上传言C3P0是因为本身的BUG问题,然而今天我遇到这个问题并解决了,结果发现并不是。通过配置c3p0.maxStatements=0 这种方案只是治标不治本,或者干脆无效。我上传的解决方案肯定能解决这个问题的根本原因。...

    【Linux系统无法访问MySQL数据库怎么办】-sql无法访问数据库-.doc

    当遇到无法访问MySQL数据库时,可能会出现如描述中的异常情况:“ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@75d634ea -- APPARENT DEADLOCK!...

    Mastering Python for Networking and Security

    Meanwhile, Python is being used for increasingly advanced tasks, with the latest update introducing many new packages. This book focuses on leveraging these updated packages to build a secure network...

    Local apparent and latent direction extraction for palmprint recognition

    Direction information of the palmprint provides one of the most promising features for palmprint recognition. However, more existing direction-based methods only extract the surface direction features...

    power_flow.zip_apparent_流动_流动方程_能量方程_能量流动

    "power_flow.zip_apparent_流动_流动方程_能量方程_能量流动"这个标题暗示了我们正在探讨的是电力系统的功率流分析,这涉及到电能如何在电网中传输。"apparent flow"(视在流动)和"流动方程"可能指的是电路理论中的...

    深度学习MATLAB工具包-DeepLearnToolbox-master.zip

    It is inspired by the human brain's apparent deep (layered, hierarchical) architecture. A good overview of the theory of Deep Learning theory is [Learning Deep Architectures for AI]...

    apparent contour-开源

    "Apparent Contour" 是一个开源项目,专注于处理三维(3D)模型的外观轮廓。在计算机图形学中,外观轮廓是指当一个3D对象被渲染时,由于法线(normal)与观察者视线(view direction)垂直而形成的边缘。这些轮廓在...

    computer vision

    Humans perceive the three-dimensional structure of the world with apparent ease. However, despite all of the recent advances in computer vision research, the dream of having a computer interpret an ...

    OpenCV.2.Computer.Vision.Application.Programming.Cookbook

    This chapter will teach you the basic elements of OpenCV and will show ...obtain strange behaviors, or if your application crashes without apparent reasons, that could be a symptom of incompatibilities.

    游戏编程精粹8--随书光盘源代码(part1/2)

    3.7 Embracing Chaos Theory: Generating Apparent Unpredictability through Deterministic Systems 288 3.8 Needs-Based AI 302 3.9 A Framework for Emotional Digital Actors 312 3.10 Scalable Dialog ...

    游戏编程精粹8--随书光盘源代码(part2/2)

    3.7 Embracing Chaos Theory: Generating Apparent Unpredictability through Deterministic Systems 288 3.8 Needs-Based AI 302 3.9 A Framework for Emotional Digital Actors 312 3.10 Scalable Dialog ...

    A Matlab toolbox for Deep Learning.

    A Matlab toolbox for Deep Learning. Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data. It is inspired by the human brain's apparent deep ...

    Apparent_Resistivity_Error.rar_电法_计算视电阻率误差

    程序语言为Fortran,计算速度快,程序可改性也很强,欢迎学习电法的同行来下载!

Global site tag (gtag.js) - Google Analytics