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

最新文章

  1. Jquery 轮播图简易框架
  2. WaitForMultipleObjects返回失败原因之一
  3. 基于android平台的出题软件---- 每日30题
  4. SQL注入原理
  5. Oracle 12c 数据库中scott用户不存在的解决方法
  6. Android的主要组件
  7. 设计模式-结合Android代码
  8. BZOJ 2152: 聪聪可可 点分治
  9. MongoDB在windows下安装配置
  10. Ionic集成ArcGIS JavaScript API.md
  11. Java之枚举----小试牛刀练习
  12. [ETL] Flume 理论与demo(Taildir Source &amp; Hdfs Sink)
  13. java 基础之 反射技术
  14. Python跨目录调程序
  15. ELK Redis高性能加速
  16. useradd密码无效
  17. Perl 文件处理范例
  18. Android Studio 检查Top Activity
  19. Flex自动回收导致监听不到ModuleEvent.READY事件
  20. 移动距离|2015年蓝桥杯B组题解析第八题-fishers

热门文章

  1. 轻松编写 C++ 单元测试
  2. [Python爬虫] 之十一:Selenium +phantomjs抓取活动行中会议活动信息
  3. Python程序员技能表—446家知名企业的Py招聘信息(转载)
  4. [视频解说]Java(JDK的下载安装及第一个程序执行)
  5. URLRewrite地址重定向的实现
  6. RocketMQ 拉取消息-文件获取
  7. JVM组成部分以及内存模型
  8. Swing的GUI组件得到焦点
  9. UVa145 Gondwanaland Telecom
  10. STL源码剖析(set/map)