title: Initializing C3P0 connection pool takes 2 min
body: <p>I can't wrap my head around why the initialization of a c3p0 connection pool takes 2 min in my Hibernate application.</p>
  
  <p>This is in my Hibernate.cfg.xml:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
          &lt;property name="connection.url"/&gt;
          &lt;property name="connection.default_schema"/&gt;
          &lt;property name="connection.username"/&gt;
          &lt;property name="connection.password"/&gt; 
  
          &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
          &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
          &lt;property name="hibernate.c3p0.acquire_increment"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.c3p0.min_size"&gt;3&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_size"&gt;10&lt;/property&gt;
          &lt;property name="hibernate.c3p0.timeout"&gt;300&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_statements"&gt;50&lt;/property&gt;
          &lt;property name="hibernate.c3p0.idle_test_period"&gt;3000&lt;/property&gt;
          &lt;property name="hibernate.c3p0."&gt;&lt;/property&gt;
  
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="format_sql"&gt;false&lt;/property&gt;
  
          &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
   &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>The connection settings are set in my HibernateUtil file when building the session factory.</p>
  
  <p>The pool is initialize when the first transaction in my tests is openend.
  Connecting and querying the db works just fine afterwards, it only hangs on the following line for a while before it will start. I formated the output a bit as I assume the problem may be with one of the settings mentioned here.:</p>
  
  <pre><code>INFO: Initializing c3p0 pool... 
  com.mchange.v2.c3p0.PoolBackedDataSource@30670080 [
    connectionPoolDataSource -&gt; com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@ecfec4d0 [
      acquireIncrement -&gt; 1,
      acquireRetryAttempts -&gt; 30,
      acquireRetryDelay -&gt; 1000,
      autoCommitOnClose -&gt; false,
      automaticTestTable -&gt; null,
      breakAfterAcquireFailure -&gt; false,
      checkoutTimeout -&gt; 0,
      connectionCustomizerClassName -&gt; null,
      connectionTesterClassName -&gt; com.mchange.v2.c3p0.impl.DefaultConnectionTester,        
      debugUnreturnedConnectionStackTraces -&gt; false,
      factoryClassLocation -&gt; null,
      forceIgnoreUnresolvedTransactions -&gt; false,
      identityToken -&gt; I-REMOVED-THIS,
      idleConnectionTestPeriod -&gt; 3000,
      initialPoolSize -&gt; 3,
      maxAdministrativeTaskTime -&gt; 0,
      maxConnectionAge -&gt; 0,
      maxIdleTime -&gt; 300,
      maxIdleTimeExcessConnections -&gt; 0,
      maxPoolSize -&gt; 10,
      maxStatements -&gt; 50,
      maxStatementsPerConnection -&gt; 0,
      minPoolSize -&gt; 3,
      nestedDataSource -&gt; com.mchange.v2.c3p0.DriverManagerDataSource@b17e5c65 [
        description -&gt; null,
        driverClass -&gt; null,
        factoryClassLocation -&gt; null,
        identityToken -&gt; I-REMOVED-THIS,
        jdbcUrl -&gt; jdbc:postgresql://URL-TO-MY_DB,
        properties -&gt; {user=******, password=******, default_schema=}
      ],
      preferredTestQuery -&gt; null,
      propertyCycle -&gt; 0,
      testConnectionOnCheckin -&gt; false,
      testConnectionOnCheckout -&gt; false,
      unreturnedConnectionTimeout -&gt; 0,
      usesTraditionalReflectiveProxies -&gt; false;
      userOverrides: {}
    ],
    dataSourceName -&gt; null,
    factoryClassLocation -&gt; null,
    identityToken -&gt; I-REMOVED-THIS,
    numHelperThreads -&gt; 3
  ]
  </code></pre>
  
  <p>It's the first time I'm using Hibernate and c3p0 and I was expecting it to be much quicker when starting the pool? Is it a misconception of mine?</p>
  
  <p>It's no difference between using the remote DB nor a local PostgreSQL instance.</p>
  
  <p>(Edit: This is not true. I made a mistake when comparing local and remote db server. Locally, initialization is pretty much immediately, remotely it takes around 2 minutes.)</p>
  
  <p>Edit2: <a href="https://gist.github.com/6cba1ae8b2982cec2afa" rel="noreferrer" title="Log">Here</a> is a log of the connection process.</p>