commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Dwinnell" <PDwinn...@SciQuest.com>
Subject DBCP - AbandonedObjectPool
Date Wed, 18 Dec 2002 19:24:39 GMT

I'm trying to use AbandonedObjectPool to close out borrowed connections
after they've been idle for a certain amount of time.  I used the code below
to create the DataSource.  In the example below, I set up the pool so that a
borrowed connection should only be allowed to remain idle for 10 seconds.
Now, I get a connection from the dataSource, sleep for 60 seconds.  After
the first 10 seconds I would have expected the connection to be closed out
by the pool.  When the 60 seconds is up the connection works fine.  Does
anyone have an idea of what I should be doing differently? 


AbandonedConfig config = new AbandonedConfig();
config.setRemoveAbandoned(true);
config.setRemoveAbandonedTimeout(10);
config.setLogAbandoned(true);

AbandonedObjectPool aop = new AbandonedObjectPool(null,config);

ConnectionFactory connectionFactory =
    new DriverManagerConnectionFactory( strURI , null);

PoolableConnectionFactory poolableConnectionFactory =
    new PoolableConnectionFactory(connectionFactory, aop,
                        null, null, false, true);

PoolingDataSource dataSource =
    new PoolingDataSource(aop);

//****************************************************

Connection conn = dataSource.getConnection();
try{
    Thread.sleep(60*1000);
}catch(InterruptedException exc){
    exc.printStackTrace();
}
Statement stmt = conn.createStatement();
ResultSet rs= stmt.executeQuery("select * form dual");












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