You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Paul Dwinnell <PD...@SciQuest.com> on 2002/12/18 20:24:39 UTC
DBCP - AbandonedObjectPool
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");