title: how to determine c3p0 max_statements
body: <p>I'm wondering how to properly determine what value to use for c3p0 max_statements. I've experienced some caching dead locks which seems to point back to my max_statements configuration based on all the SO Q&amp;A I've read. </p>
  
  <p>I'm using mysql and the deadlock appears to happen when I'm doing some multi threading where I have 4 active threads. </p>
  
  <p>My configuration</p>
  
  <pre><code>&lt;property name="hibernate.connection.provider_class"&gt;org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider&lt;/property&gt;
  &lt;property name="hibernate.c3p0.min_size"&gt;10&lt;/property&gt;
  &lt;property name="hibernate.c3p0.max_statements"&gt;50&lt;/property&gt;
  &lt;property name="hibernate.c3p0.max_size"&gt;50&lt;/property&gt;
  &lt;property name="hibernate.c3p0.idle_test_period"&gt;1800&lt;/property&gt;
  &lt;property name="hibernate.c3p0.timeout"&gt;3600&lt;/property&gt;
  </code></pre>
  
  <p>The exception</p>
  
  <pre><code>[WARN] async.ThreadPoolAsynchronousRunner com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@72df1587 -- APPARENT DEADLOCK!!! Complete Status:
      Managed Threads: 3
      Active Threads: 3
      Active Tasks:
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask@e877a61
              on thread: C3P0PooledConnectionPoolManager[identityToken-&gt;1hge0wd9a1o1iea71i8u346|1a799bb]-HelperThread-#2
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask@109b1150
              on thread: C3P0PooledConnectionPoolManager[identityToken-&gt;1hge0wd9a1o1iea71i8u346|1a799bb]-HelperThread-#0
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask@3eb42946
              on thread: C3P0PooledConnectionPoolManager[identityToken-&gt;1hge0wd9a1o1iea71i8u346|1a799bb]-HelperThread-#1
      Pending Tasks:
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@52729f95
  Pool thread stack traces:
      Thread[C3P0PooledConnectionPoolManager[identityToken-&gt;1hge0wd9a1o1iea71i8u346|1a799bb]-HelperThread-#0,5,main]
          com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:2765)
          com.mysql.jdbc.StatementImpl.close(StatementImpl.java:541)
          com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:53)
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask.run(GooGooStatementCache.java:938)
          com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
      Thread[C3P0PooledConnectionPoolManager[identityToken-&gt;1hge0wd9a1o1iea71i8u346|1a799bb]-HelperThread-#1,5,main]
          com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:2765)
          com.mysql.jdbc.StatementImpl.close(StatementImpl.java:541)
          com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:53)
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask.run(GooGooStatementCache.java:938)
          com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
      Thread[C3P0PooledConnectionPoolManager[identityToken-&gt;1hge0wd9a1o1iea71i8u346|1a799bb]-HelperThread-#2,5,main]
          com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:2765)
          com.mysql.jdbc.StatementImpl.close(StatementImpl.java:541)
          com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:53)
          com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask.run(GooGooStatementCache.java:938)
          com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
  </code></pre>
  
  <p>So my question is how do I determine what these values should be. I'm sure there must be away to do this without guessing. </p>
  
  <p>Articles I've read</p>
  
  <p><a href="https://stackoverflow.com/questions/2920740/should-i-activate-c3p0-statement-pooling">should i activate c3p0 statement pooling?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16230863/how-to-trace-and-prevent-the-deadlock-appeared-in-c3po-which-is-running-in-seper">How to trace and prevent the deadlock appeared in c3po which is running in seperate processes?</a></p>