title: Validation Query in org.apache.tomcat.jdbc.pool
body: <p>I'm recntly doing some tests with the new Tomcat JDBC connection pool (<code>org.apache.tomcat.jdbc.pool</code>, version 7.0.20). My understanding of using the validation query is, when I'm e.g. rebooting the database and the pool looses all connections, it automatically tries to recover them. </p>
  
  <p>Here the initialization Code:</p>
  
  <p>...</p>
  
  <pre><code>PoolProperties p = new PoolProperties();
  p.setUrl(connString);
  p.setDriverClassName("org.postgresql.Driver");
  p.setJmxEnabled(true);
  p.setTestWhileIdle(false);
  p.setTestOnBorrow(true);
  p.setValidationQuery("SELECT version();");
  p.setTestOnReturn(false);
  p.setValidationInterval(30000);
  p.setTimeBetweenEvictionRunsMillis(30000);
  p.setMaxActive(maximumDbConnections);
  p.setInitialSize(1);
  p.setMaxWait(10000);
  p.setRemoveAbandonedTimeout(60);
  p.setMinEvictableIdleTimeMillis(30000);
  p.setMinIdle(minimumIdleDbConnections);
  p.setMaxIdle(maximumIdleDbConnections);
  p.setLogAbandoned(true);
  p.setRemoveAbandoned(true);
  p.setInitSQL("SET application_name = 'My Server'");
  datasource = new DataSource();
  datasource.setPoolProperties(p);
  </code></pre>
  
  <p>...</p>
  
  <p>In then I start a timer and everytime it fires, I get the connection from the pool:</p>
  
  <p>...</p>
  
  <pre><code>Connection conn = App.datasource.getConnection();
  </code></pre>
  
  <p>...</p>
  
  <p>When Im booting the database, it's not trying to revover the connections as expacted, I always receive the following exception:</p>
  
  <pre><code>[2011-08-22 23:50:53,066][871009][ERROR]{DbPollThread - 1}  [0144] SQLException while checking for hangig jobs
  java.sql.SQLException: Connection has already been closed.
      at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:118)
      at $Proxy2.prepareStatement(Unknown Source)
      at org.voxtelo.faxserver.internal.database.FaxDatabaseHandler.resetOrDeactivateHangingJobs(FaxDatabaseHandler.java:404)
      at org.voxtelo.faxserver.internal.database.FaxDatabaseHandler.pollJobsFromDB(FaxDatabaseHandler.java:884)
      at org.voxtelo.faxserver.internal.database.FaxDatabaseHandler.access$1(FaxDatabaseHandler.java:882)
      at org.voxtelo.faxserver.internal.database.FaxDatabaseHandler$PollDatabaseTask.run(FaxDatabaseHandler.java:940)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:680)
  </code></pre>