DBCP removeAbandoned not working!
843859Aug 29 2005 — edited May 23 2007hi all,
I am using DBCP 1.2.1. Why is the abandoned connection NOT returned after 5 seconds?
Please help.
Thanks,
Joe.
The output of the following program is as follows:
<output>
Loading underlying JDBC driver.
Creating connection 1.
AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@21b6d)
LogAbandoned: false
RemoveAbandoned: true
RemoveAbandonedTimeout: 300
Creating connection 2.
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
</output>
<code>
import java.sql.Connection;
import javax.sql.DataSource;
import java.util.Properties;
import org.apache.commons.dbcp.BasicDataSourceFactory;
public class ManualPoolingDriverExample2 {
public static void main(String[] args) {
System.out.println("Loading underlying JDBC driver.");
Properties dataSourceProperties = new Properties();
dataSourceProperties.setProperty("factory", "org.apache.commons.dbcp.BasicDataSourceFactory");
dataSourceProperties.setProperty("driverClassName", "com.progress.sql.jdbc.JdbcProgressDriver");
dataSourceProperties.setProperty("url", "jdbc:jdbcprogress:T:localhost:9199:test");
dataSourceProperties.setProperty("username", "joe");
dataSourceProperties.setProperty("password", "joe1");
dataSourceProperties.setProperty("maxActive", "1");
dataSourceProperties.setProperty("maxWait", "10000"); // wait for 10 secs
dataSourceProperties.setProperty("removeAbandoned", "true");
dataSourceProperties.setProperty("logAbandoned", "false");
dataSourceProperties.setProperty("removeAbandonedTimeout", "5"); // return abandonded connections after 5 secs
try {
DataSource dataSource = BasicDataSourceFactory.createDataSource(dataSourceProperties);
Connection conn = null;
System.out.println("Creating connection 1.");
conn = dataSource.getConnection();
System.out.println("Creating connection 2.");
conn = dataSource.getConnection();
System.out.println("Done creating connections.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
</code>