commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vijay Anjur" <vijay.an...@gmail.com>
Subject Tomcat: DBCP Connection Pooling issue
Date Mon, 13 Mar 2006 21:04:50 GMT
Hi,

I am having trouble with dbcp connection pooling with JTDS driver.

When I close the connection, pool never seem to shrink after the idle time
specified in server.xml has passed.
When I check using GetNumIdle() method, it always shows zero, even after the
connections are closed.Any Ideas?

 Here is my server config & the code.

 <Resource

      name="jdbc/somedb"

      auth="Container"

      type="javax.sql.DataSource"

      factory="org.apache.commons.dbcp.BasicDataSourceFactory"

      driverClassName="net.sourceforge.jtds.jdbc.Driver"

      validationQuery="Select 1"

      maxWait="6000"

      username="username"

      password="something"

      testOnBorrow="true"

      testOnReturn="false"

      testWhileIdle="true"

      url="jdbc:jtds:sqlserver://server:16778"

      initialSize="8"

      numTestsPerEvictionRun="6"

      timeBetweenEvictionRunsMillis="10000"

      minEvictableIdleTimeMillis="100000"

      removeAbandoned="true"

      removeAbandonedTimeout="300"

      logAbandoned="true"

      maxActive="20"

      maxIdle="5"

      minIdle="0"/>



 Code snippet:

   private InitialContext ic = null;

   private Context envCtx = null;

   private static DataSource dsINTLDB;

   private static GenericObjectPool poolINTLDB;

   private static PoolingDataSource pdsINTLDB;

   private static BasicDataSource bdsINTLDB;



  ic = new InitialContext();

  envCtx = (Context) ic.lookup("java:comp/env");

  dsINTLDB = (DataSource) envCtx.lookup("ds/somedb");



 if (dsINTLDB != null)

 {

            bdsINTLDB = (BasicDataSource)dsINTLDB;

ConnectionFactory cf1 = new DataSourceConnectionFactory(dsINTLDB);

poolINTLDB = new GenericObjectPool(null,

                                               bdsINTLDB.getMaxActive(),

                                               (byte)1,

                                               bdsINTLDB.getMaxWait(),

                                               bdsINTLDB.getMaxIdle(),

                                               bdsINTLDB.getMinIdle(),

                                               bdsINTLDB.getTestOnBorrow(),

                                               bdsINTLDB.getTestOnReturn(),


bdsINTLDB.getTimeBetweenEvictionRunsMillis(),


bdsINTLDB.getNumTestsPerEvictionRun(),


bdsINTLDB.getMinEvictableIdleTimeMillis(),

                                               bdsINTLDB.getTestWhileIdle()
);



PoolableConnectionFactory pcf1 = new PoolableConnectionFactory(cf1,
poolINTLDB, null, null, false, true);

pcf1.setValidationQuery(bdsINTLDB.getValidationQuery());

pdsINTLDB = new PoolingDataSource(poolINTLDB);

}



Connection c = pdsINTLDB.getConnection();

//use connection.



c.close();





===============================================================================

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message