You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Vijay Anjur <vi...@gmail.com> on 2006/03/12 21:31:19 UTC

Fwd: DBCP Connection pooling with JTDS Driver.

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();





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