title: C3P0 apparent deadlock when the threads are all empty?
body: <p>I'm using C3P0 as a connection pool in Tomcat, and I'm seeing very worrying errors:</p>
  
  <pre><code>2010-09-16 13:25:00,160 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@43502400 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
  2010-09-16 13:25:01,407 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@43502400 -- APPARENT DEADLOCK!!! Complete Status:
    Managed Threads: 10
    Active Threads: 0
    Active Tasks:
    Pending Tasks:
      com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@6e4151a7
    Pool thread stack traces:
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#6,5,main]
      java.lang.Object.wait(Native Method)
      com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
      java.lang.Object.wait(Native Method)
      com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
      java.lang.Object.wait(Native Method)
      com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
      java.lang.Object.wait(Native Method)
      com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5,5,main]
      java.lang.Object.wait(Native Method)
      com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4,5,main]
      java.lang.Object.wait(Native Method)
  
  ... many more, exact same stack trace
  </code></pre>
  
  <p>Line 534 is:</p>
  
  <pre><code> while (true) {
     Runnable myTask;
     synchronized ( ThreadPoolAsynchronousRunner.this ) {
       while ( !should_stop &amp;&amp; pendingTasks.size() == 0 )
         ThreadPoolAsynchronousRunner.this.wait( POLL_FOR_STOP_INTERVAL ); // &lt;- here
       if (should_stop) ...
  </code></pre>
  
  <p>It looks very much like all the threads are idle.  They're waiting for work.  0 active threads, and only 1 task to complete.  Any clues on what's going wrong?</p>
  
  <p>Here's the configuration:</p>
  
  <pre><code>ds.setUser(userName);
  ds.setPassword(password);
  ds.setMaxPoolSize(16);
  ds.setMaxConnectionAge(1800);
  ds.setAcquireRetryAttempts(4);
  ds.setMaxIdleTime(900);
  ds.setNumHelperThreads(10);
  ds.setCheckoutTimeout(1000);
  </code></pre>