glenn 02/05/16 14:30:22 Modified: catalina/src/share/org/apache/naming/factory DbcpDataSourceFactory.java Log: Add support for the new DBCP Features. Three new DBCP parameters were added: removeAbandoned - True or false. If true abandoned db connections are removed after the removeAbandonedTimout is exceeded if the dbcp is nearing exhaustion. removeAbandonedTimeout - Time in seconds since a connection was last used before it is considered abandoned. logAbandoned - True or false. If true Exception stack traces are created so that the source of an abandoned db connection can be logged. Revision Changes Path 1.6 +59 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/DbcpDataSourceFactory.java Index: DbcpDataSourceFactory.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/DbcpDataSourceFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DbcpDataSourceFactory.java 10 May 2002 03:08:35 -0000 1.5 +++ DbcpDataSourceFactory.java 16 May 2002 21:30:22 -0000 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/DbcpDataSourceFactory.java,v 1.5 2002/05/10 03:08:35 remm Exp $ - * $Revision: 1.5 $ - * $Date: 2002/05/10 03:08:35 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/DbcpDataSourceFactory.java,v 1.6 2002/05/16 21:30:22 glenn Exp $ + * $Revision: 1.6 $ + * $Date: 2002/05/16 21:30:22 $ * * ==================================================================== * @@ -74,10 +74,11 @@ import javax.naming.Reference; import javax.naming.RefAddr; import javax.naming.spi.ObjectFactory; +import org.apache.commons.dbcp.AbandonedConfig; +import org.apache.commons.dbcp.AbandonedObjectPool; import org.apache.commons.dbcp.DriverManagerConnectionFactory; import org.apache.commons.dbcp.PoolableConnectionFactory; import org.apache.commons.dbcp.PoolingDataSource; -import org.apache.commons.pool.impl.GenericObjectPool; import org.apache.naming.ResourceRef; @@ -111,10 +112,20 @@ * connections from this pool. If specified, this query * <strong>MUST</strong> be an SQL SELECT that returns at least one row. * </li> + * <li><strong>removeAbandoned</strong> - Remove abandoned connections which were + * never closed by the code which opened them. A check for abandoned connections + * is performed when the pool is nearly exhausted. Any connections who's last + * use is older than the removeAbandonedTimeout are closed and recycled.</li> + * <li><strong>removeAbandonedTimeout</strong> - Timeout in seconds. When removal + * of abandoned connections is performed only connections who's last use is + * older than the removeAbandonedTimout are removed and recycled.</li> + * <li><strong>logAbandoned</strong> - Log stack traces for any dbcp connections + * which were removed after being abandoned without being closed.</li> * </ul> * * @author Craig R. McClanahan - * @version $Revision: 1.5 $ $Date: 2002/05/10 03:08:35 $ + * @author Glenn L. Nielsen + * @version $Revision: 1.6 $ $Date: 2002/05/16 21:30:22 $ */ public class DbcpDataSourceFactory @@ -194,6 +205,47 @@ if (currentRefAddr != null) validationQuery = currentRefAddr.getContent().toString(); + // Create a new abandoned config + AbandonedConfig config = null; + currentRefAddr = ref.get("removeAbandoned"); + try { + if (currentRefAddr != null) { + config = new AbandonedConfig(); + config.setRemoveAbandoned + (Boolean.valueOf + (currentRefAddr.getContent().toString()).booleanValue()); + } + } catch (Throwable t) { + log("Error setting removeAbandoned", t); + } + + currentRefAddr = ref.get("removeAbandonedTimeout"); + try { + if (currentRefAddr != null) { + if (config == null) { + config = new AbandonedConfig(); + } + config.setRemoveAbandonedTimeout + (Integer.parseInt(currentRefAddr.getContent().toString())); + } + } catch (Throwable t) { + log("Error setting removeAbandonedTimout", t); + } + + currentRefAddr = ref.get("logAbandoned"); + try { + if (currentRefAddr != null) { + if (config == null) { + config = new AbandonedConfig(); + } + config.setLogAbandoned + (Boolean.valueOf + (currentRefAddr.getContent().toString()).booleanValue()); + } + } catch (Throwable t) { + log("Error setting logAbandoned", t); + } + // Validate our configuration parameters if (driverClassName == null) throw new NamingException @@ -239,7 +291,7 @@ // Create a new data source instance // FIXME - Cache this for later reuse??? - GenericObjectPool connectionPool = new GenericObjectPool(null); + AbandonedObjectPool connectionPool = new AbandonedObjectPool(null,config); try { if (maxActive != null) connectionPool.setMaxActive(Integer.parseInt(maxActive)); @@ -265,7 +317,7 @@ PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, validationQuery, - false, true); + false, true, config); dataSource = new PoolingDataSource(connectionPool); } catch(Throwable t) { log("Cannot create DataSource, Exception",t);
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>