commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vijay Anjur" <vijay.an...@gmail.com>
Subject Re: Tomcat: DBCP Connection Pooling issue
Date Thu, 16 Mar 2006 00:17:10 GMT
When I did what you mentioned,  the other parameters such as 'testOnBorrow',
'ValidationQuery' etc, were not set to the pool.

I just casted the DataSource to BasicDataSource so that I can ensure those
properties are set to the pool.

For example, testOnBorrow property was always false when I did what you
mentioned. Somehow it was  defaulting to GenericObjectPool's default value…



On 3/13/06, Sandy McArthur <sandymac@apache.org> wrote:
>
> Vijay,
>
> I don't get what you are trying to do.
>
> Why are you getting a DataSource from JNDI and then using the settings
> from it to create an ObjectPool? Shouldn't it be sufficient to simply
> do:
>
> Connection c = dsINTLDB.getConnection();
> // use connection.
> c.close();
>
> On 3/13/06, Vijay Anjur <vijay.anjur@gmail.com> wrote:
> > 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();
>
>
> --
> Sandy McArthur
>
> "He who dares not offend cannot be honest."
> - Thomas Paine
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

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