You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/05/02 03:58:40 UTC

svn commit: r1098458 - in /commons/proper/dbcp/trunk/src: changes/ java/org/apache/commons/dbcp/ site/xdoc/ test/org/apache/commons/dbcp/

Author: psteitz
Date: Mon May  2 01:58:39 2011
New Revision: 1098458

URL: http://svn.apache.org/viewvc?rev=1098458&view=rev
Log:
Exposed GenericObjectPool's softMinEvictableIdleTimeMillis property
for configuration and use by BasicDataSource.
JIRA: DBCP-334
Reported and patched by Alberto Mozzone

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
    commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1098458&r1=1098457&r2=1098458&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Mon May  2 01:58:39 2011
@@ -41,6 +41,10 @@ The <action> type attribute can be add,u
     <release version="2.0" date="TBD" description="TBD">
     </release>
     <release version="1.4.1" date="TBD" description="TBD">
+      <action dev="psteitz" issue="DBCP-334" type="update" due-to="Alberto Mozzone">
+        Exposed GenericObjectPool's softMinEvictableIdleTimeMillis property for
+        configuration and use by BasicDataSource.
+      </action>
       <action dev="psteitz" issue="DBCP-337" type="fix" due-to="Rob Gansevles">
         Made equals reflexive in DelegatingStatement (and subclasses), DelegatingMetaData,
         DelegatingResultSet and PoolingDriver#PoolGuardConnectionWrapper.

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java?rev=1098458&r1=1098457&r2=1098458&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java Mon May  2 01:58:39 2011
@@ -618,7 +618,7 @@ public class BasicDataSource implements 
      * Returns the value of the {@link #timeBetweenEvictionRunsMillis}
      * property.
      * 
-     * @return the time (in miliseconds) between evictor runs
+     * @return the time (in milliseconds) between evictor runs
      * @see #timeBetweenEvictionRunsMillis
      */
     public synchronized long getTimeBetweenEvictionRunsMillis() {
@@ -700,6 +700,57 @@ public class BasicDataSource implements 
             connectionPool.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
         }
     }
+    
+    /**
+     * The minimum amount of time a connection may sit idle in the pool before
+     * it is eligible for eviction by the idle object evictor, with the extra
+     * condition that at least "minIdle" connections remain in the pool.
+     * Note that {@code minEvictableIdleTimeMillis} takes precedence over this
+     * parameter.  See {@link #getSoftMinEvictableIdleTimeMillis()}.
+     */
+    private long softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+    
+    /**
+     * Sets the minimum amount of time a connection may sit idle in the pool
+     * before it is eligible for eviction by the idle object evictor, with the
+     * extra condition that at least "minIdle" connections remain in the pool.
+     *
+     * @param softMinEvictableIdleTimeMillis minimum amount of time a
+     * connection may sit idle in the pool before it is eligible for eviction,
+     * assuming there are minIdle idle connections in the pool.
+     * @since 1.4.1
+     * @see #getSoftMinEvictableIdleTimeMillis
+     */
+    public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
+        this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+        if (connectionPool != null) {
+            connectionPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
+        }
+    }
+    
+    /**
+     * <p>Returns the minimum amount of time a connection may sit idle in the
+     * pool before it is eligible for eviction by the idle object evictor, with
+     * the extra condition that at least "minIdle" connections remain in the
+     * pool.</p>
+     * 
+     * <p>When {@link #getMinEvictableIdleTimeMillis() miniEvictableIdleTimeMillis} 
+     * is set to a positive value, miniEvictableIdleTimeMillis is examined
+     * first by the idle connection evictor - i.e. when idle connections are
+     * visited by the evictor, idle time is first compared against
+     * {@code minEvictableIdleTimeMillis} (without considering the number of idle
+     * connections in the pool) and then against 
+     * {@code softMinEvictableIdleTimeMillis}, including the {@code minIdle},
+     * constraint.</p>
+     *
+     * @return minimum amount of time a connection may sit idle in the pool before
+     * it is eligible for eviction, assuming there are minIdle idle connections
+     * in the pool
+     * @since 1.4.1
+     */
+    public synchronized long getSoftMinEvictableIdleTimeMillis() {
+        return softMinEvictableIdleTimeMillis;
+    }
 
     /**
      * The indication of whether objects will be validated by the idle object

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java?rev=1098458&r1=1098457&r2=1098458&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java Mon May  2 01:58:39 2011
@@ -61,6 +61,7 @@ public class BasicDataSourceFactory impl
     private final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
     private final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
     private final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
+    private final static String PROP_SOFTMINEVICTABLEIDLETIMEMILLIS = "softMinEvictableIdleTimeMillis";
     private final static String PROP_TESTWHILEIDLE = "testWhileIdle";
     private final static String PROP_PASSWORD = "password";
     private final static String PROP_URL = "url";
@@ -98,6 +99,7 @@ public class BasicDataSourceFactory impl
         PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
         PROP_NUMTESTSPEREVICTIONRUN,
         PROP_MINEVICTABLEIDLETIMEMILLIS,
+        PROP_SOFTMINEVICTABLEIDLETIMEMILLIS,
         PROP_TESTWHILEIDLE,
         PROP_PASSWORD,
         PROP_URL,
@@ -274,6 +276,11 @@ public class BasicDataSourceFactory impl
         if (value != null) {
             dataSource.setMinEvictableIdleTimeMillis(Long.parseLong(value));
         }
+        
+        value = properties.getProperty(PROP_SOFTMINEVICTABLEIDLETIMEMILLIS);
+        if (value != null) {
+            dataSource.setSoftMinEvictableIdleTimeMillis(Long.parseLong(value));
+        }
 
         value = properties.getProperty(PROP_TESTWHILEIDLE);
         if (value != null) {

Modified: commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml?rev=1098458&r1=1098457&r2=1098458&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml (original)
+++ commons/proper/dbcp/trunk/src/site/xdoc/configuration.xml Mon May  2 01:58:39 2011
@@ -241,7 +241,22 @@ one row.
       is eligable for eviction by the idle object evictor (if any).
    </td>
 </tr>
-  <tr>
+<tr>
+   <td>softMiniEvictableIdleTimeMillis</td>
+   <td>-1</td>
+   <td>
+      The minimum amount of time a connection may sit idle in the pool before
+      it is eligible for eviction by the idle connection evictor, with
+      the extra condition that at least "minIdle" connections remain in the
+      pool. When miniEvictableIdleTimeMillis is set to a positive value,
+      miniEvictableIdleTimeMillis is examined first by the idle 
+      connection evictor - i.e. when idle connections are visited by the
+      evictor, idle time is first compared against miniEvictableIdleTimeMillis
+      (without considering the number of idle connections in the pool) and then
+      against softMinEvictableIdleTimeMillis, including the minIdle constraint.
+   </td>
+ </tr>
+ <tr>
      <td>connectionInitSqls</td>
      <td>null</td>
      <td>

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java?rev=1098458&r1=1098457&r2=1098458&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java (original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestBasicDataSourceFactory.java Mon May  2 01:58:39 2011
@@ -71,6 +71,7 @@ public class TestBasicDataSourceFactory 
         properties.setProperty("connectionInitSqls", "SELECT 1;SELECT 2");
         properties.setProperty("timeBetweenEvictionRunsMillis", "1000");
         properties.setProperty("minEvictableIdleTimeMillis", "2000");
+        properties.setProperty("softMinEvictableIdleTimeMillis", "3000");
         properties.setProperty("numTestsPerEvictionRun", "2");
         properties.setProperty("testWhileIdle", "true");
         properties.setProperty("accessToUnderlyingConnectionAllowed", "true");
@@ -106,6 +107,7 @@ public class TestBasicDataSourceFactory 
         assertEquals("SELECT 2", ds.connectionInitSqls.get(1));
         assertEquals(1000, ds.getTimeBetweenEvictionRunsMillis());
         assertEquals(2000, ds.getMinEvictableIdleTimeMillis());
+        assertEquals(3000, ds.getSoftMinEvictableIdleTimeMillis());
         assertEquals(2, ds.getNumTestsPerEvictionRun());
         assertEquals(true, ds.getTestWhileIdle());
         assertEquals(true, ds.isAccessToUnderlyingConnectionAllowed());