I am using Hibernate along with MySQL 5.1.30.
I have the following libraries:
- c3p0-0.0.1.2.jar
- MySQL-socket-Java-5.0.3-bin.jar
- hibernate3.jar
I use hibernate.cfg.xml to configure:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="connection.url">jdbc:mysql://localhost/fooDatatbase</property> <property name="connection.username">foo</property> <property name="connection.password">foo123</property> <property name="hibernate.c3p0.min_size">5</property> <property name="hibernate.c3p0.max_size">20</property> <property name="hibernate.c3p0.timeout">300</property> <property name="hibernate.c3p0.max_statements">50</property> <property name="hibernate.c3p0.idle_test_periods">3000</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="current_session_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="show_sql">true</property> <mapping resource="databaselayer/mail/Mail.hbm.xml"/> <mapping resource="databaselayer/courses/Course.hbm.xml"/> <mapping resource="databaselayer/price/Price.hbm.xml"/> <mapping resource="databaselayer/contact/Contact.hbm.xml"/> <mapping resource="databaselayer/artists/Musician.hbm.xml"/> <mapping resource="databaselayer/concerts/Concert.hbm.xml"/> <mapping resource="databaselayer/welcome/Welcome.hbm.xml"/> <mapping resource="databaselayer/information/Information.hbm.xml"/> </session-factory> </hibernate-configuration>
The JAVA column with the hibernate book explains c3p0 configuration options:
- hibernate.c3p0.min_size This is the minimum number of JDBC connections that C3P0 always supports.
- hibernate.c3p0.max_size . This is the maximum number of connections in the pool. An exception occurs at run time if this number is exhausted.
- hibernate.c3p0.timeout . Specify the waiting period (in this case 300 seconds) after which a free connection is removed from the pool.)
- hibernate.c3p0.max_statements The maximum number of statements to be cached. Caching prepared statements is essential in order to work best with Hibernate.
- hibernate.c3p0.idle_test_periods This is the iddle time in seconds before the connection is automatically verified.
I am using Java 1.5.0_09 and tomcat 6.0 . I have three applications deployed to tomcat. Each of them uses hibernate with a configuration file almost equivalent to the above (only username, database_name, password and display change changes).
Unfortunately, with the settings above, after several hours of work, I get some unpleasant deadlock errors that end up killing tomcat.
Jan 22, 2009 3:29:07 PM com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@2437d -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! Jan 22, 2009 3:29:07 PM com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1dc5cb7 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! Jan 22, 2009 3:29:07 PM com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@9cd2ef -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! Jan 22, 2009 3:29:07 PM com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@4af355 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! Jan 22, 2009 3:29:07 PM com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1275fcb -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! Jan 22, 2009 3:29:35 PM com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
This seems to be a mistake that some people have already received. I changed my settings trying to follow the workaround described here http://forum.hibernate.org/viewtopic.php?p=2386237 so that:
<property name="hibernate.c3p0.acquire_increment">1</property> <property name="hibernate.c3p0.min_size">0</property> <property name="hibernate.c3p0.max_size">48</property> <property name="hibernate.c3p0.timeout">0</property> <property name="hibernate.c3p0.max_statements">0</property>
With the new settings, I do not get Deadlock, but I get:
WARNING: SQL Error: 0, SQLState: 08S01 Jan 24, 2009 5:53:37 AM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.io.EOFException STACKTRACE: java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
Does anyone know what I'm doing wrong, and how can I configure c3p0 correctly?