You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/08/13 20:10:42 UTC

[commons-pool] branch master updated (c93f5bf -> 84d1a37)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git.


    from c93f5bf  Bump spotbugs from 4.2.3 to 4.3.0 and ignore new medium warnings EI_EXPOSE_REP and EI_EXPOSE_REP2.
     new a02bb61  Fix Javadoc.
     new 2667e02  Reimplement BaseGenericObjectPool.maxBorrowWait as a Duration instead of a long.
     new 9e4e21b  Note previous change.
     new 84d1a37  Use assertThrows.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  6 +++++
 .../commons/pool2/impl/BaseGenericObjectPool.java  | 29 ++++++++++++----------
 .../pool2/impl/TestGenericKeyedObjectPool.java     |  7 +-----
 3 files changed, 23 insertions(+), 19 deletions(-)

[commons-pool] 03/04: Note previous change.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 9e4e21be58eb49c6b7ea30cb5b755851e848f083
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 13 16:05:08 2021 -0400

    Note previous change.
---
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1b245c1..a32f636 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,6 +68,9 @@ The <action> type attribute can be add,update,fix,remove.
       Fix field label in NoSuchElementException message for GenericObjectPool.borrowObject(Duration): From borrowMaxWaitMillis to borrowMaxWaitDuration.
     </action>
     <action dev="ggregory" type="fix" due-to="Gary Gregory">
+      Reimplement DefaultPooledObject.getIdleDuration() using Duration computation.
+    </action>
+    <action dev="ggregory" type="fix" due-to="Gary Gregory">
       Reimplement BaseGenericObjectPool.maxBorrowWait as a Duration instead of a long.
     </action>
     <!-- UPDATES -->

[commons-pool] 02/04: Reimplement BaseGenericObjectPool.maxBorrowWait as a Duration instead of a long.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 2667e022900ec9fa2406c3cfef338d7d2abf6f5f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 13 16:04:56 2021 -0400

    Reimplement BaseGenericObjectPool.maxBorrowWait as a Duration instead of
    a long.
---
 src/changes/changes.xml                            |  3 +++
 .../commons/pool2/impl/BaseGenericObjectPool.java  | 27 ++++++++++++----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c640a2c..1b245c1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,9 @@ The <action> type attribute can be add,update,fix,remove.
     <action dev="ggregory" type="fix" due-to="Gary Gregory">
       Fix field label in NoSuchElementException message for GenericObjectPool.borrowObject(Duration): From borrowMaxWaitMillis to borrowMaxWaitDuration.
     </action>
+    <action dev="ggregory" type="fix" due-to="Gary Gregory">
+      Reimplement BaseGenericObjectPool.maxBorrowWait as a Duration instead of a long.
+    </action>
     <!-- UPDATES -->
     <action dev="ggregory" type="update" due-to="Dependabot">
       Bump checkstyle from 8.45 to 8.45.1 #93.
diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
index d6699f6..ad864ae 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.TimerTask;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 import javax.management.InstanceAlreadyExistsException;
@@ -356,7 +357,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
     private Evictor evictor; // @GuardedBy("evictionLock")
     EvictionIterator evictionIterator; // @GuardedBy("evictionLock")
 
-    /*
+    /**
      * Class loader for evictor thread to use since, in a JavaEE or similar
      * environment, the context class loader for the evictor thread may not have
      * visibility of the correct factory. See POOL-161. Uses a weak reference to
@@ -377,7 +378,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
     private final StatsStore idleTimes = new StatsStore(MEAN_TIMING_STATS_CACHE_SIZE);
     private final StatsStore waitTimes = new StatsStore(MEAN_TIMING_STATS_CACHE_SIZE);
 
-    private final AtomicLong maxBorrowWaitTimeMillis = new AtomicLong();
+    private final AtomicReference<Duration> maxBorrowWaitDuration = new AtomicReference<>(Duration.ZERO);
 
     private volatile SwallowedExceptionListener swallowedExceptionListener;
     private volatile boolean messageStatistics;
@@ -679,7 +680,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
      * @return maximum wait time in milliseconds since the pool was created
      */
     public final long getMaxBorrowWaitTimeMillis() {
-        return maxBorrowWaitTimeMillis.get();
+        return maxBorrowWaitDuration.get().toMillis();
     }
 
     /**
@@ -1015,12 +1016,12 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
         // Simply listed in AB order.
         return String.format(
                 "activeTimes=%s, blockWhenExhausted=%s, borrowedCount=%,d, closed=%s, createdCount=%,d, destroyedByBorrowValidationCount=%,d, " +
-                        "destroyedByEvictorCount=%,d, evictorShutdownTimeoutDuration=%s, fairness=%s, idleTimes=%s, lifo=%s, maxBorrowWaitTimeMillis=%,d, " +
+                        "destroyedByEvictorCount=%,d, evictorShutdownTimeoutDuration=%s, fairness=%s, idleTimes=%s, lifo=%s, maxBorrowWaitDuration=%s, " +
                         "maxTotal=%s, maxWaitDuration=%s, minEvictableIdleDuration=%s, numTestsPerEvictionRun=%s, returnedCount=%s, " +
                         "softMinEvictableIdleDuration=%s, testOnBorrow=%s, testOnCreate=%s, testOnReturn=%s, testWhileIdle=%s, " +
                         "durationBetweenEvictionRuns=%s, waitTimes=%s",
                 activeTimes.getCurrentValues(), blockWhenExhausted, borrowedCount.get(), closed, createdCount.get(), destroyedByBorrowValidationCount.get(),
-                destroyedByEvictorCount.get(), evictorShutdownTimeoutDuration, fairness, idleTimes.getCurrentValues(), lifo, maxBorrowWaitTimeMillis.get(),
+                destroyedByEvictorCount.get(), evictorShutdownTimeoutDuration, fairness, idleTimes.getCurrentValues(), lifo, maxBorrowWaitDuration.get(),
                 maxTotal, maxWaitDuration, minEvictableIdleDuration, numTestsPerEvictionRun, returnedCount, softMinEvictableIdleDuration, testOnBorrow,
                 testOnCreate, testOnReturn, testWhileIdle, durationBetweenEvictionRuns, waitTimes.getCurrentValues());
     }
@@ -1886,8 +1887,8 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
         builder.append(idleTimes);
         builder.append(", waitTimes=");
         builder.append(waitTimes);
-        builder.append(", maxBorrowWaitTimeMillis=");
-        builder.append(maxBorrowWaitTimeMillis);
+        builder.append(", maxBorrowWaitDuration=");
+        builder.append(maxBorrowWaitDuration);
         builder.append(", swallowedExceptionListener=");
         builder.append(swallowedExceptionListener);
     }
@@ -1902,16 +1903,18 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
         borrowedCount.incrementAndGet();
         idleTimes.add(p.getIdleDuration());
         waitTimes.add(waitDuration);
-        final long waitTimeMillis = waitDuration.toMillis();
 
         // lock-free optimistic-locking maximum
-        long currentMaxMillis;
+        Duration currentMaxDuration;
         do {
-            currentMaxMillis = maxBorrowWaitTimeMillis.get();
-            if (currentMaxMillis >= waitTimeMillis) {
+            currentMaxDuration = maxBorrowWaitDuration.get();
+//            if (currentMaxDuration >= waitDuration) {
+//                break;
+//            }
+            if (currentMaxDuration.compareTo(waitDuration) >= 0) {
                 break;
             }
-        } while (!maxBorrowWaitTimeMillis.compareAndSet(currentMaxMillis, waitTimeMillis));
+        } while (!maxBorrowWaitDuration.compareAndSet(currentMaxDuration, waitDuration));
     }
 
     /**

[commons-pool] 04/04: Use assertThrows.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 84d1a37bdff45771dd1b3cc26227d2b00d870f8d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 13 16:05:30 2021 -0400

    Use assertThrows.
---
 .../org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java  | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
index 4c584b8..5800273 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -2048,12 +2048,7 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
         gkoPool.setMaxTotal(0);
         gkoPool.setBlockWhenExhausted(false);
 
-        try {
-            gkoPool.borrowObject("a");
-            fail("Expected NoSuchElementException");
-        } catch(final NoSuchElementException e) {
-            // expected
-        }
+        assertThrows(NoSuchElementException.class, () -> gkoPool.borrowObject("a"));
     }
 
 

[commons-pool] 01/04: Fix Javadoc.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit a02bb6153ab9821bfb84a7bd1397e9943c2b6e7a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 13 15:36:50 2021 -0400

    Fix Javadoc.
---
 src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
index 950c733..d6699f6 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
@@ -1896,7 +1896,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
      * Updates statistics after an object is borrowed from the pool.
      *
      * @param p object borrowed from the pool
-     * @param waitDuration time (in milliseconds) that the borrowing thread had to wait
+     * @param waitDuration that the borrowing thread had to wait
      */
     final void updateStatsBorrow(final PooledObject<T> p, final Duration waitDuration) {
         borrowedCount.incrementAndGet();