Search code examples
javahibernatec3p0database-deadlocks

how to get rid of c3p0 deadlock error


I'm using hibernate 4.3.6 with c3p0 0.9.2.1 and I'm getting the following error very frequently:

ThreadPoolAsynchronousRunner:778 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@9abc33e -- Running DeadlockDetector[Exiting. No pending tasks.]

This slows down the server and I have no idea what's causing it and how to get rig of it.

This is my hibernate.config file:

<!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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://ip:port/app?autoReconnect=true&amp;useUnicode=true&amp;createDatabaseIfNotExist=true&amp;characterEncoding=utf-8</property>
    <property name="hibernate.connection.username">username</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.connection.isolation">2</property>
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
     <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
     <property name="hibernate.c3p0.min_size">5</property>
      <property name="hibernate.c3p0.max_size">100</property>
      <property name="hibernate.c3p0.timeout">300</property>
      <property name="hibernate.c3p0.max_statements">50</property>
      <property name="hibernate.c3p0.idle_test_period">3000</property>
     <mapping class="server.c1"/>          
     <mapping class="server.c2"/>
     <mapping class="server.c3"/>
     <mapping class="server.c4"/>
     <mapping class="server.c5"/>
   </session-factory> 
</hibernate-configuration> 

In addition I also have a c3p0.properties file:

c3p0.testConnectionOnCheckout=true
c3p0.privilegeSpawnedThreads=true
c3p0.contextClassLoaderSource=library

There are a lot of questions about it but I couldn't find a concrete solution.


Solution

  • I had a similar problem with c3p0. My final solution was use this connection pool https://github.com/brettwooldridge/HikariCP