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 2023/03/05 14:27:09 UTC

[commons-pool] branch master updated (5a284d64 -> 69b2b4d8)

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 5a284d64 Make private test class static
     new bb4735fb Javadoc
     new 108735e2 Javadoc
     new 69d85af5 Use java.time
     new 69b2b4d8 More precise measurements

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:
 .../org/apache/commons/pool2/PooledObject.java     |  2 +-
 .../pool2/impl/DefaultPooledObjectInfoMBean.java   |  6 +--
 .../commons/pool2/impl/GenericKeyedObjectPool.java |  5 ++-
 .../commons/pool2/impl/GenericObjectPool.java      |  9 ++---
 .../apache/commons/pool2/ObjectPoolIssue326.java   |  5 ++-
 .../commons/pool2/performance/PerformanceTest.java | 45 +++++++++++-----------
 6 files changed, 37 insertions(+), 35 deletions(-)


[commons-pool] 01/04: 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 bb4735fb27529fd66f31e4e5b493e2b4acf69f79
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 5 08:43:27 2023 -0500

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

diff --git a/src/main/java/org/apache/commons/pool2/PooledObject.java b/src/main/java/org/apache/commons/pool2/PooledObject.java
index 6403d33b..bdb550e6 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObject.java
+++ b/src/main/java/org/apache/commons/pool2/PooledObject.java
@@ -150,7 +150,7 @@ public interface PooledObject<T> extends Comparable<PooledObject<T>> {
 
     /**
      * Gets the time (using the same basis as
-     * {@link System#currentTimeMillis()}) that this object was created.
+     * {@link java.time.Clock#instant()}) that this object was created.
      *
      * @return The creation time for the wrapped object.
      * @deprecated Use {@link #getCreateInstant()} which offers the best precision.


[commons-pool] 03/04: Use java.time

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 69d85af508968dc8c93632056043b4de54fca00a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 5 08:55:54 2023 -0500

    Use java.time
---
 .../org/apache/commons/pool2/impl/GenericKeyedObjectPool.java    | 5 +++--
 .../java/org/apache/commons/pool2/impl/GenericObjectPool.java    | 9 ++++-----
 src/test/java/org/apache/commons/pool2/ObjectPoolIssue326.java   | 5 +++--
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
index 2badcb31..2ac96297 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
@@ -17,6 +17,7 @@
 package org.apache.commons.pool2.impl;
 
 import java.time.Duration;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.Deque;
 import java.util.HashMap;
@@ -422,7 +423,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
         final boolean blockWhenExhausted = getBlockWhenExhausted();
 
         boolean create;
-        final long waitTimeMillis = System.currentTimeMillis();
+        final Instant waitTime = Instant.now();
         final ObjectDeque<T> objectDeque = register(key);
 
         try {
@@ -502,7 +503,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
             deregister(key);
         }
 
-        updateStatsBorrow(p, Duration.ofMillis(System.currentTimeMillis() - waitTimeMillis));
+        updateStatsBorrow(p, Duration.between(waitTime, Instant.now()));
 
         return p.getObject();
     }
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
index f6349c16..d74079de 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
@@ -17,6 +17,7 @@
 package org.apache.commons.pool2.impl;
 
 import java.time.Duration;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.NoSuchElementException;
 import java.util.Set;
@@ -285,7 +286,7 @@ public class GenericObjectPool<T, E extends Exception> extends BaseGenericObject
         final boolean blockWhenExhausted = getBlockWhenExhausted();
 
         boolean create;
-        final long waitTimeMillis = System.currentTimeMillis();
+        final Instant waitTime = Instant.now();
 
         while (p == null) {
             create = false;
@@ -361,7 +362,7 @@ public class GenericObjectPool<T, E extends Exception> extends BaseGenericObject
             }
         }
 
-        updateStatsBorrow(p, Duration.ofMillis(System.currentTimeMillis() - waitTimeMillis));
+        updateStatsBorrow(p, Duration.between(waitTime, Instant.now()));
 
         return p.getObject();
     }
@@ -544,9 +545,7 @@ public class GenericObjectPool<T, E extends Exception> extends BaseGenericObject
             }
 
             // Do not block more if maxWaitTimeMillis is set.
-            if (create == null &&
-                localMaxWaitTimeMillis > 0 &&
-                 System.currentTimeMillis() - localStartTimeMillis >= localMaxWaitTimeMillis) {
+            if (create == null && localMaxWaitTimeMillis > 0 && System.currentTimeMillis() - localStartTimeMillis >= localMaxWaitTimeMillis) {
                 create = Boolean.FALSE;
             }
         }
diff --git a/src/test/java/org/apache/commons/pool2/ObjectPoolIssue326.java b/src/test/java/org/apache/commons/pool2/ObjectPoolIssue326.java
index 6e5d78a8..6f4555b1 100644
--- a/src/test/java/org/apache/commons/pool2/ObjectPoolIssue326.java
+++ b/src/test/java/org/apache/commons/pool2/ObjectPoolIssue326.java
@@ -18,6 +18,7 @@
 package org.apache.commons.pool2;
 
 import java.time.Duration;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.NoSuchElementException;
@@ -137,7 +138,7 @@ public final class ObjectPoolIssue326 {
         // 4 core box.
         // too many doesn't reproduce it ever, too few doesn't either.
         final ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
-        final long startTimeMillis = System.currentTimeMillis();
+        final Instant startTime = Instant.now();
         long testIter = 0;
         try {
             while (true) {
@@ -152,7 +153,7 @@ public final class ObjectPoolIssue326 {
                 }
             }
         } finally {
-            System.out.println("Time: " + (System.currentTimeMillis() - startTimeMillis) / 1000.0);
+            System.out.println("Time: " + Duration.between(startTime, Instant.now()));
             service.shutdown();
         }
     }


[commons-pool] 02/04: 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 108735e2e262bad80f1f18abe9feae93b5db0624
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 5 08:46:19 2023 -0500

    Javadoc
---
 .../org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java b/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java
index f7c33e42..33ce08a7 100644
--- a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java
+++ b/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java
@@ -41,7 +41,7 @@ public interface DefaultPooledObjectInfoMBean {
 
     /**
      * Gets the time (using the same basis as
-     * {@link System#currentTimeMillis()}) that pooled object was created.
+     * {@link java.time.Clock#instant()}) that pooled object was created.
      *
      * @return The creation time for the pooled object
      */
@@ -57,7 +57,7 @@ public interface DefaultPooledObjectInfoMBean {
 
     /**
      * Gets the time (using the same basis as
-     * {@link System#currentTimeMillis()}) the polled object was last borrowed.
+     * {@link java.time.Clock#instant()}) the polled object was last borrowed.
      *
      * @return The time the pooled object was last borrowed
      */
@@ -81,7 +81,7 @@ public interface DefaultPooledObjectInfoMBean {
 
     /**
      * Gets the time (using the same basis as
-     * {@link System#currentTimeMillis()})the wrapped object was last returned.
+     * {@link java.time.Clock#instant()})the wrapped object was last returned.
      *
      * @return The time the object was last returned
      */


[commons-pool] 04/04: More precise measurements

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 69b2b4d84319b901e318ff14a954431884668c1d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 5 09:10:36 2023 -0500

    More precise measurements
---
 .../commons/pool2/performance/PerformanceTest.java | 45 +++++++++++-----------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java b/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java
index 0fddf1dd..ea29789e 100644
--- a/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java
+++ b/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.commons.pool2.performance;
 
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
@@ -34,22 +35,22 @@ public class PerformanceTest {
 
     class PerfTask implements Callable<TaskStats> {
         final TaskStats taskStats = new TaskStats();
-        long borrowTimeMillis;
-        long returnTimeMillis;
+        long borrowTimeNanos;
+        long returnTimeNanos;
 
         @Override
         public TaskStats call() {
                runOnce(); // warmup
                for (int i = 0; i < nrIterations; i++) {
                    runOnce();
-                   taskStats.totalBorrowTime += borrowTimeMillis;
-                   taskStats.totalReturnTime += returnTimeMillis;
+                   taskStats.totalBorrowNanos += borrowTimeNanos;
+                   taskStats.totalReturnNanos += returnTimeNanos;
                    taskStats.nrSamples++;
                    if (logLevel >= 2) {
                        final String name = "thread" + Thread.currentThread().getName();
                        System.out.println("result " + taskStats.nrSamples + '\t' +
-                               name + '\t' + "borrow time: " + borrowTimeMillis + '\t' +
-                               "return time: " + returnTimeMillis + '\t' + "waiting: " +
+                               name + '\t' + "borrow time: " + Duration.ofNanos(borrowTimeNanos) + '\t' +
+                               "return time: " + Duration.ofNanos(returnTimeNanos) + '\t' + "waiting: " +
                                taskStats.waiting + '\t' + "complete: " +
                                taskStats.complete);
                    }
@@ -66,9 +67,9 @@ public class PerformanceTest {
                         "   waiting: " + taskStats.waiting +
                         "   complete: " + taskStats.complete);
             }
-            final long bbeginMillis = System.currentTimeMillis();
+            final long bbeginNanos = System.nanoTime();
             final Integer o = pool.borrowObject();
-            final long bendMillis = System.currentTimeMillis();
+            final long bendNanos = System.nanoTime();
             taskStats.waiting--;
 
             if (logLevel >= 3) {
@@ -78,13 +79,13 @@ public class PerformanceTest {
                         "   complete: " + taskStats.complete);
             }
 
-            final long rbeginMillis = System.currentTimeMillis();
+            final long rbeginNanos = System.nanoTime();
             pool.returnObject(o);
-            final long rendMillis = System.currentTimeMillis();
+            final long rendNanos = System.nanoTime();
             Thread.yield();
             taskStats.complete++;
-            borrowTimeMillis = bendMillis - bbeginMillis;
-            returnTimeMillis = rendMillis - rbeginMillis;
+            borrowTimeNanos = bendNanos - bbeginNanos;
+            returnTimeNanos = rendNanos - rbeginNanos;
         } catch (final Exception e) {
             e.printStackTrace();
         }
@@ -93,8 +94,8 @@ public class PerformanceTest {
     private static class TaskStats {
         public int waiting;
         public int complete;
-        public long totalBorrowTime;
-        public long totalReturnTime;
+        public long totalBorrowNanos;
+        public long totalReturnNanos;
         public int nrSamples;
     }
 
@@ -177,25 +178,25 @@ public class PerformanceTest {
                 if (taskStats != null) {
                     aggregate.complete += taskStats.complete;
                     aggregate.nrSamples += taskStats.nrSamples;
-                    aggregate.totalBorrowTime += taskStats.totalBorrowTime;
-                    aggregate.totalReturnTime += taskStats.totalReturnTime;
+                    aggregate.totalBorrowNanos += taskStats.totalBorrowNanos;
+                    aggregate.totalReturnNanos += taskStats.totalReturnNanos;
                     aggregate.waiting += taskStats.waiting;
                 }
             }
         }
 
+        final Duration totalBorrowDuration = Duration.ofNanos(aggregate.totalBorrowNanos);
+        final Duration totalReturnDuration = Duration.ofNanos(aggregate.totalReturnNanos);
         System.out.println("-----------------------------------------");
         System.out.println("nrIterations: " + iterations);
         System.out.println("nrThreads: " + nrThreads);
         System.out.println("maxTotal: " + maxTotal);
         System.out.println("maxIdle: " + maxIdle);
         System.out.println("nrSamples: " + aggregate.nrSamples);
-        System.out.println("totalBorrowTime: " + aggregate.totalBorrowTime);
-        System.out.println("totalReturnTime: " + aggregate.totalReturnTime);
-        System.out.println("avg BorrowTime: " +
-                aggregate.totalBorrowTime / aggregate.nrSamples);
-        System.out.println("avg ReturnTime: " +
-                aggregate.totalReturnTime / aggregate.nrSamples);
+        System.out.println("totalBorrowTime: " + totalBorrowDuration);
+        System.out.println("totalReturnTime: " + totalReturnDuration);
+        System.out.println("avg BorrowTime: " + totalBorrowDuration.dividedBy(aggregate.nrSamples));
+        System.out.println("avg ReturnTime: " + totalReturnDuration.dividedBy(aggregate.nrSamples));
 
         threadPool.shutdown();
     }