C3P0 Connection Pool not working in Servlet/Tomcat

423 views Asked by At

Created a Datasource class based on C3P0 ComboPooledDataSource class. It works with testing code but won't work in servlet under tomcat container. Does anyone know why?

class Datasource{
   private ComboPooledDataSource cpds;
   private Datasoruce datasource;

   private Datasource(){
   //setup cpds
   cpds.new ComboPooledDataSource();
   cpds.setUser("abcd");
   ...
 }

 public static getInstance(){
     if( datasource == null ) datasource = new Datasource();
     return datasource;
 }

  public Connection getConnection(){
     return cpds.getConnection();
 }
}

//test code works if put in indepedent main() with multithreading.
  Datasource ds = Datasource.getInstance();
  Connection conn = ds.getConnection();

//Above test code won't work if put inside servlet doGet() with tomcat.

The error is "An attempt by a client to checkout a Connection has timed out right at the line of getConnection().

0

There are 0 answers