---
title: "C3P0错误APPARENT DEADLOCK!!!解决"
author: "east_java"
date: "2008-10-18T22:22:50Z"
tags: []
categories: ["企业架构"]
slug: "c3p0-apparent-deadlock"
draft: false
lastmod: "2008-10-18T22:22:50Z"
id: 254786
url: "https://japi.iteye.com/blog/254786"
---

在使用C3P0的过程中出现了好多错误.最长见就是死锁,占用资源比较大.

对于死锁问题http://japi.iteye.com/blog/243702.找到了解决方案(不能完全保证,但在负载测试中,还没有出现问题)

问题关键是参数的设置

> 
> <!--JDBC的标准参数，用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 
> 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 
> 如果maxStatements与maxStatementsPerConnection均为0，则缓存被关闭。Default: 0--> 
> <property name="maxStatements">100</property> 
> 
> <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --> 
> <property name="maxStatementsPerConnection"></property> 
> 


解决的方法是:

> In hibernate.cfg.xml: 
> <property name="hibernate.c3p0.max_statements">0</property>  
> 
> 
> In c3p0.properties: 
> c3p0.maxStatements=0 
> c3p0.maxStatementsPerConnection=100 
> 

来源于:http://forum.hibernate.org/viewtopic.php?p=2386237
http://forum.hibernate.org/viewtopic.php?t=947246&start=0&postdays=0&postorder=asc&highlight=apparent+deadlock+c3p0&sid=6fcfab70cff3588bf010914df8dbbb90

http://www.mchange.com/projects/c3p0/index.html#c3p0_properties