dirkv 2004/02/07 06:54:33
Modified: dbcp/src/java/org/apache/commons/dbcp BasicDataSource.java
BasicDataSourceFactory.java
Log:
Implementation of enhancement 25514
- add initialSize parameter to do pre-loading of the connection pool
Revision Changes Path
1.33 +30 -5
jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java
Index: BasicDataSource.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- BasicDataSource.java 25 Jan 2004 19:57:38 -0000 1.32
+++ BasicDataSource.java 7 Feb 2004 14:54:33 -0000 1.33
@@ -227,6 +227,22 @@
}
/**
+ * The initial number of connections that are created when the pool
+ * is started.
+ * @since 1.2
+ */
+ protected int initialSize = 0;
+
+ public synchronized int getInitialSize() {
+ return this.initialSize;
+ }
+
+ public synchronized void setInitialSize(int initialSize) {
+ this.initialSize = initialSize;
+ this.restartNeeded = true;
+ }
+
+ /**
* The maximum number of milliseconds that the pool will wait (when there
* are no available connections) for a connection to be returned before
* throwing an exception, or -1 to wait indefinitely.
@@ -883,14 +899,23 @@
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
- throw new SQLNestedException("Cannot create PoolableConnectionFactory",
e);
+ throw new SQLNestedException("Cannot create PoolableConnectionFactory
(" + e.getMessage() + ")", e);
}
// Create and return the pooling data source to manage the connections
dataSource = new PoolingDataSource(connectionPool);
((PoolingDataSource)
dataSource).setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
dataSource.setLogWriter(logWriter);
- return (dataSource);
+
+ try {
+ for (int i = 0 ; i < initialSize ; i++) {
+ connectionPool.addObject();
+ }
+ } catch (Exception e) {
+ throw new SQLNestedException("Error preloading the connection pool", e);
+ }
+
+ return dataSource;
}
private static void validateConnectionFactory(PoolableConnectionFactory
connectionFactory) throws Exception {
1.14 +10 -4
jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
Index: BasicDataSourceFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- BasicDataSourceFactory.java 25 Jan 2004 19:49:27 -0000 1.13
+++ BasicDataSourceFactory.java 7 Feb 2004 14:54:33 -0000 1.14
@@ -85,7 +85,6 @@
* @author Dirk Verbeeck
* @version $Revision$ $Date$
*/
-
public class BasicDataSourceFactory implements ObjectFactory {
private final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
@@ -96,6 +95,7 @@
private final static String PROP_MAXACTIVE = "maxActive";
private final static String PROP_MAXIDLE = "maxIdle";
private final static String PROP_MINIDLE = "minIdle";
+ private final static String PROP_INITIALSIZE = "initialSize";
private final static String PROP_MAXWAIT = "maxWait";
private final static String PROP_TESTONBORROW = "testOnBorrow";
private final static String PROP_TESTONRETURN = "testOnReturn";
@@ -124,6 +124,7 @@
PROP_MAXACTIVE,
PROP_MAXIDLE,
PROP_MINIDLE,
+ PROP_INITIALSIZE,
PROP_MAXWAIT,
PROP_TESTONBORROW,
PROP_TESTONRETURN,
@@ -260,6 +261,11 @@
value = properties.getProperty(PROP_MINIDLE);
if (value != null) {
dataSource.setMinIdle(Integer.parseInt(value));
+ }
+
+ value = properties.getProperty(PROP_INITIALSIZE);
+ if (value != null) {
+ dataSource.setInitialSize(Integer.parseInt(value));
}
value = properties.getProperty(PROP_MAXWAIT);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]