2018-01-04 15:02:03,319 ---com.mchange.v2.async.ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@4d6c4ebb -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

先说说APPARENT DEADLOCK!!!​什么情况下会抛出这样的异常?

通过看源码,源码是个好东西,有个检测死锁的DeadlockDetector​,每隔一段时间就会检测一次,是一个TimerTask,里面是这样写的:

current = (LinkedList) pendingTasks.clone();​

if ( current.equals( last ) ){

logger.warning(this + " -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!");

}​

解释一下current和last

代码里这两个对象分别是一个LinkedList

current用来记录当前等待获取连接的AcquireTask​

last用来记录上次等待获取连接的AcquireTask​

如果二者相等的话,C3P0认为是死锁,抛出警告

什么情况下会出现这样的异常?

1.数据库连接不上的话,会报这样的异常​,检查数据源配置是否正确?

我在本地测试,没有配置​checkoutTime(获取连接的超时时间)这个参数,20根线程并发发起连接,检测死锁的线程的线程,试想,在某次检测过程中发现18个等待连接的任务,那么在下一次检测的时候,这18个连接任务,仍旧没有连上数据库,可能是数据库连接配置错误,检查数据源配置信息,满足出这个错误的条件,当然就会报APPARENT DEADLOCK!!!

2.在缓存中存在Statement,来说说这个

网上有人回答这个问题,说是设置c3p0.maxStatements=0,为啥设置一下这个就OK了呢?

这里说说我个人思考,因为在数据库里的Statement的缓存都是在连接基础上了,存在缓存了,这里我理解就是就是占用了数据库的连接数,而申请新的连接的过程中,在达到连接数​最大时,检测死锁的线程又可能会检测出2次等待连接是AcquireTask相等,就会抛出异常。

My workaround: 
In hibernate.cfg.xml:

Code:
<property name="hibernate.c3p0.max_statements">0</property>

In c3p0.properties:

Code:
c3p0.maxStatements=0
c3p0.maxStatementsPerConnection=100

For such setting my multithreaded applications runs with no APPARENT DEADLOCK error (finally and ... hopefully that this problem is really solved). 
My app running quite fast so I guess (and I believe) that Statement caching is working. Statements caching is crucial for me because of performance. In other words I couldn't just turn Statement caching off (*). 
As far as I can see turning Statement caching off (this global statement caching) is one (or maybe the only one) solution to get rid of APPARENT DEADLOCK errors. 
Damn, I really would like to have time to have a look at c3p0 source code and figure out where is the reason of those fu!@#$% errors (Oracle JDBC or Hibernate or c3p0).

总结一下:就是用户申请新的连接的时候,旧的连接又没有及时释放,那么就会抛出​APPARENT DEADLOCK!!!的异常了。

本文转自:http://blog.sina.com.cn/s/blog_7b9948fd0102vyuh.html

c3p0 APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks的更多相关文章

  1. eclipse run on server 时 报的错误APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

    写这篇日记记录一下自己的愚蠢行为. 具体报错如下: 信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ ...

  2. 解决 APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tas

    报错信息:APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! 在网上查了一下,大部分网友分析是c ...

  3. C3P0连接池问题,APPARENT DEADLOCK!!! Creating emergency..... [问题点数:20分,结帖人lovekong]

    采用c3p0连接池,每次调试程序,第一次访问时(Tomcat服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...

  4. C3P0 APPARENT DEADLOCK

    一,c3p0执行一段时间后报错例如以下 W 07-26_00:58:27 ThreadPoolAsynchronousRunner.java 608 com.mchange.v2.async.Thre ...

  5. APPARENT DEADLOCK!!!c3p0数据库连接池死锁问题

    项目进行压力测试的时候,运行大概1小时候,后台抛出以下异常: Nov 9, 2012 1:41:59 AM com.mchange.v2.async.ThreadPoolAsynchronousRun ...

  6. com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector APPARENT DEADLOCK

    最近在IDEA中启动Tomcat经常会碰到这个错误,起初.一直没在意,现在碰到的次数多了,就去查看下这个问题,现描述如下: =2018-01-08 14:27:30,216 WARN [com.mch ...

  7. com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1035079 -- APPARENT DEADLOCK!!! Complete Status:

    com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1035079 -- APPARENT DEADLOCK!!! C ...

  8. 【Oracle-DBA】Oracle连接非常慢APPARENT DEADLOCK

    我是一名软件包工头,哪里有问题就干哪里. 这次是 Oracle 出毛病了,我就临时兼了DBA的职,没办法,谁叫我是工头呢.打开百度就开干. 这次关键词是:APPARENT DEADLOCK!!! 丫的 ...

  9. C/C++ Threads): Creating worker threads that will be listening to jobs and executing them concurrently when wanted

    Suppose we have two workers. Each worker has an id of 0 and 1. Also suppose that we have jobs arrivi ...

随机推荐

  1. iOS:iOS开发系列–打造自己的“美图秀秀”(下)

    来源: KenshinCui 链接:http://www.cnblogs.com/kenshincui/p/3959951.html 运行效果: 其他图形上下文 前面我们也说过,Quartz 2D的图 ...

  2. Linux编程中的坑——C++中exit和return的区别

    今天遇到一个坑,折腾了一天才把这个坑填上,情况是这样的: 写了段代码,在main()函数中创建一个分离线程,结果这个线程什么都没干就直接挂掉了,代码长这样: int main() { 创建一个分离线程 ...

  3. hdu 1408 acdearm &quot;Money, Money, Money&quot;

    #include<stdio.h> int main() { long long int x; while(~scanf("%lld",&x)) { if(x% ...

  4. PLSQL Developer连接远程Oracle方法(非安装client)

    远程连接Oracle比較麻烦,通常须要安装oracle的客户端才干实现. 通过instantclient能够比較简单的连接远程的Oracle. 1.新建文件夹D:\Oracle_Cleint用于存放相 ...

  5. mysql索引处理

    1.索引作用在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万倍.例如,有3个 ...

  6. dhclient 简介

    dhclient 就和它名字一样,用来通过 dhcp 协议配置本机的网络接口. 使用方法就是 #dhclient ifN # ifN 就是 ifconfig 中输出的接口名称,etc. eth0,wl ...

  7. C# 和 Java的区别积累

    1.类的继承 A.C#用 ":"符号: B.Java用关键字 extends: 2.接口的实现 A.C#用 ":"符号: B.Java用关键字 implemen ...

  8. Android Exception 10(server)' ~ Channel is unrecoverably broken and will be disposed!)

    08-11 19:22:35.028: W/MemoryDealer(2123): madvise(0x43e16000, 12288, MADV_REMOVE) returned Operation ...

  9. 08-hibernate注解-多对多双向外键关联

    多对多双向外键 双方持有对方的集合对象 其中一方设置: //教师类 @ManyToMany(mappedBy="teachers")   //mappedby表示教师交给学生来控制 ...

  10. 浅谈ThreadPool 线程池(引用)

    出自:http://www.cnblogs.com/xugang/archive/2010/04/20/1716042.html 浅谈ThreadPool 线程池 相关概念: 线程池可以看做容纳线程的 ...