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/02/15 18:44:12 UTC
[commons-pool] branch master updated (0da5c54 -> 91a81e5)
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 0da5c54 Use the scale in the var name.
new eb00d5b Add and use java.time.Duration APIs for AbandonedConfig timeouts instead of using ints as seconds. - Add AbandonedConfig.getRemoveAbandonedTimeoutDuration() - Add AbandonedConfig.setRemoveAbandonedTimeout(Duration)
new 650bddc Refactor constant. Remove initialization to default values.
new 35b582c Bullet-proof test tear-down against NPE when an actual test fails.
new ca34e91 Add and use java.time.Duration APIs for AbandonedConfig timeouts instead of using ints as seconds. - Add GenericObjectPool.getRemoveAbandonedTimeoutDuration()
new 91a81e5 Switch internals to java.time.Duration. Add Duration constants based on existing milliseconds constants.
The 5 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:
pom.xml | 6 +-
src/changes/changes.xml | 11 +-
.../apache/commons/pool2/impl/AbandonedConfig.java | 50 +++++-
.../commons/pool2/impl/BaseGenericObjectPool.java | 81 ++++-----
.../commons/pool2/impl/BaseObjectPoolConfig.java | 184 +++++++++++++--------
.../apache/commons/pool2/impl/EvictionTimer.java | 15 +-
.../commons/pool2/impl/GenericObjectPool.java | 30 +++-
.../pool2/impl/TestAbandonedObjectPool.java | 19 ++-
.../TestConstants.java} | 15 +-
.../pool2/impl/TestDefaultPooledObjectInfo.java | 2 +-
.../commons/pool2/impl/TestEvictionTimer.java | 10 +-
.../pool2/impl/TestGenericKeyedObjectPool.java | 101 ++++++++---
.../commons/pool2/impl/TestGenericObjectPool.java | 10 +-
.../pool2/proxy/BaseTestProxiedObjectPool.java | 5 +-
14 files changed, 349 insertions(+), 190 deletions(-)
copy src/test/java/org/apache/commons/pool2/{proxy/TestProxiedObjectPoolWithCglibProxy.java => impl/TestConstants.java} (75%)
[commons-pool] 01/05: Add and use java.time.Duration APIs for
AbandonedConfig timeouts instead of using ints as seconds. - Add
AbandonedConfig.getRemoveAbandonedTimeoutDuration() - Add
AbandonedConfig.setRemoveAbandonedTimeout(Duration)
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 eb00d5b9e9b7573c35f98ea7d31390b778b8011b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 15 10:00:17 2021 -0500
Add and use java.time.Duration APIs for AbandonedConfig timeouts instead
of using ints as seconds.
- Add AbandonedConfig.getRemoveAbandonedTimeoutDuration()
- Add AbandonedConfig.setRemoveAbandonedTimeout(Duration)
---
pom.xml | 6 +--
src/changes/changes.xml | 10 ++++-
.../apache/commons/pool2/impl/AbandonedConfig.java | 44 ++++++++++++++++++++--
.../commons/pool2/impl/GenericObjectPool.java | 12 +++---
.../pool2/impl/TestAbandonedObjectPool.java | 16 +++++---
.../apache/commons/pool2/impl/TestConstants.java | 26 +++++++++++++
.../pool2/impl/TestDefaultPooledObjectInfo.java | 2 +-
.../pool2/proxy/BaseTestProxiedObjectPool.java | 5 ++-
8 files changed, 100 insertions(+), 21 deletions(-)
diff --git a/pom.xml b/pom.xml
index 560f106..fbce2e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
</parent>
<artifactId>commons-pool2</artifactId>
- <version>2.9.1-SNAPSHOT</version>
+ <version>2.10.0-SNAPSHOT</version>
<name>Apache Commons Pool</name>
<inceptionYear>2001</inceptionYear>
@@ -158,7 +158,7 @@
<commons.module.name>org.apache.commons.pool2</commons.module.name>
<commons.rc.version>RC1</commons.rc.version>
<!-- Java 8 -->
- <commons.release.version>2.9.0</commons.release.version>
+ <commons.release.version>2.10.0</commons.release.version>
<commons.release.desc>(Java 8)</commons.release.desc>
<!-- Java 7 -->
<commons.release.2.version>2.6.2</commons.release.2.version>
@@ -185,7 +185,7 @@
<spotbugs.impl.version>4.2.0</spotbugs.impl.version>
<!-- Commons Release Plugin -->
- <commons.bc.version>2.8.1</commons.bc.version>
+ <commons.bc.version>2.9.0</commons.bc.version>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.releaseManagerName>Gary Gregory</commons.releaseManagerName>
<commons.releaseManagerKey>86fdc7e2a11262cb</commons.releaseManagerKey>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 18352ff..150db44 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -43,8 +43,14 @@ The <action> type attribute can be add,update,fix,remove.
<title>Apache Commons Pool Release Notes</title>
</properties>
<body>
- <release version="2.9.1" date="202Y-MM-DD" description="This is a MMMM release (Java 8).">
- <!-- UPDATES -->
+ <release version="2.10.0" date="202Y-MM-DD" description="This is a MMMM release (Java 8).">
+ <!-- ADD -->
+ <action dev="ggregory" type="update" due-to="Dependabot">
+ Add and use java.time.Duration APIs for AbandonedConfig timeouts instead of using ints for seconds.
+ - Add AbandonedConfig.getRemoveAbandonedTimeoutDuration()
+ - Add AbandonedConfig.setRemoveAbandonedTimeout(Duration)
+ </action>
+ <!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump spotbugs-maven-plugin from 4.0.4 to 4.2.0 #48, #53, #59.
</action>
diff --git a/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java b/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
index 85c1cc4..91e2eea 100644
--- a/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
+++ b/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
@@ -20,6 +20,7 @@ package org.apache.commons.pool2.impl;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
+import java.time.Duration;
import org.apache.commons.pool2.TrackedUse;
import org.apache.commons.pool2.UsageTracking;
@@ -102,9 +103,9 @@ public class AbandonedConfig {
}
/**
- * Timeout in seconds before an abandoned object can be removed.
+ * Timeout before an abandoned object can be removed.
*/
- private int removeAbandonedTimeout = 300;
+ private Duration removeAbandonedTimeout = Duration.ofSeconds(300);
/**
* <p>Timeout in seconds before an abandoned object can be removed.</p>
@@ -116,12 +117,47 @@ public class AbandonedConfig {
* <p>The default value is 300 seconds.</p>
*
* @return the abandoned object timeout in seconds
+ * @deprecated Use {@link #getRemoveAbandonedTimeoutDuration()}.
*/
+ @Deprecated
public int getRemoveAbandonedTimeout() {
+ return (int) this.removeAbandonedTimeout.getSeconds();
+ }
+
+ /**
+ * <p>Timeout before an abandoned object can be removed.</p>
+ *
+ * <p>The time of most recent use of an object is the maximum (latest) of
+ * {@link TrackedUse#getLastUsed()} (if this class of the object implements
+ * TrackedUse) and the time when the object was borrowed from the pool.</p>
+ *
+ * <p>The default value is 300 seconds.</p>
+ *
+ * @return the abandoned object timeout.
+ * @since 2.10.0
+ */
+ public Duration getRemoveAbandonedTimeoutDuration() {
return this.removeAbandonedTimeout;
}
/**
+ * <p>Sets the timeout before an abandoned object can be
+ * removed</p>
+ *
+ * <p>Setting this property has no effect if
+ * {@link #getRemoveAbandonedOnBorrow() removeAbandonedOnBorrow} and
+ * {@link #getRemoveAbandonedOnMaintenance() removeAbandonedOnMaintenance}
+ * are both false.</p>
+ *
+ * @param removeAbandonedTimeout new abandoned timeout
+ * @see #getRemoveAbandonedTimeout()
+ * @since 2.10.0
+ */
+ public void setRemoveAbandonedTimeout(final Duration removeAbandonedTimeout) {
+ this.removeAbandonedTimeout = removeAbandonedTimeout;
+ }
+
+ /**
* <p>Sets the timeout in seconds before an abandoned object can be
* removed</p>
*
@@ -132,9 +168,11 @@ public class AbandonedConfig {
*
* @param removeAbandonedTimeout new abandoned timeout in seconds
* @see #getRemoveAbandonedTimeout()
+ * @deprecated Use {@link #setRemoveAbandonedTimeout(Duration)}.
*/
+ @Deprecated
public void setRemoveAbandonedTimeout(final int removeAbandonedTimeout) {
- this.removeAbandonedTimeout = removeAbandonedTimeout;
+ setRemoveAbandonedTimeout(Duration.ofSeconds(removeAbandonedTimeout));
}
/**
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 6bb571b..9991926 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
@@ -282,14 +282,16 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
}
/**
- * Obtains the timeout before which an object will be considered to be
+ * Gets the timeout before which an object will be considered to be
* abandoned by this pool.
*
* @return The abandoned object timeout in seconds if abandoned object
* removal is configured for this pool; Integer.MAX_VALUE otherwise.
*
* @see AbandonedConfig#getRemoveAbandonedTimeout()
+ * @see AbandonedConfig#getRemoveAbandonedTimeoutDuration()
*/
+ @SuppressWarnings("deprecation")
@Override
public int getRemoveAbandonedTimeout() {
final AbandonedConfig ac = this.abandonedConfig;
@@ -328,7 +330,7 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
this.abandonedConfig.setLogWriter(abandonedConfig.getLogWriter());
this.abandonedConfig.setRemoveAbandonedOnBorrow(abandonedConfig.getRemoveAbandonedOnBorrow());
this.abandonedConfig.setRemoveAbandonedOnMaintenance(abandonedConfig.getRemoveAbandonedOnMaintenance());
- this.abandonedConfig.setRemoveAbandonedTimeout(abandonedConfig.getRemoveAbandonedTimeout());
+ this.abandonedConfig.setRemoveAbandonedTimeout(abandonedConfig.getRemoveAbandonedTimeoutDuration());
this.abandonedConfig.setUseUsageTracking(abandonedConfig.getUseUsageTracking());
this.abandonedConfig.setRequireFullStackTrace(abandonedConfig.getRequireFullStackTrace());
}
@@ -1070,7 +1072,7 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
// Generate a list of abandoned objects to remove
final long nowMillis = System.currentTimeMillis();
final long timeoutMillis =
- nowMillis - (abandonedConfig.getRemoveAbandonedTimeout() * 1000L);
+ nowMillis - abandonedConfig.getRemoveAbandonedTimeoutDuration().toMillis();
final ArrayList<PooledObject<T>> remove = new ArrayList<>();
final Iterator<PooledObject<T>> it = allObjects.values().iterator();
while (it.hasNext()) {
@@ -1202,7 +1204,7 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
* {@link #_maxActive} objects created at any one time.
*/
private final AtomicLong createCount = new AtomicLong(0);
- private long makeObjectCount = 0;
+ private long makeObjectCount;
private final Object makeObjectCountLock = new Object();
private final LinkedBlockingDeque<PooledObject<T>> idleObjects;
@@ -1211,7 +1213,7 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
"org.apache.commons.pool2:type=GenericObjectPool,name=";
// Additional configuration properties for abandoned object tracking
- private volatile AbandonedConfig abandonedConfig = null;
+ private volatile AbandonedConfig abandonedConfig;
@Override
protected void toStringAppendFields(final StringBuilder builder) {
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
index e576a85..39886aa 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
@@ -45,9 +45,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* TestCase for AbandonedObjectPool
*/
public class TestAbandonedObjectPool {
+
private GenericObjectPool<PooledTestObject> pool = null;
private AbandonedConfig abandonedConfig = null;
+ @SuppressWarnings("deprecation")
@BeforeEach
public void setUp() throws Exception {
abandonedConfig = new AbandonedConfig();
@@ -57,6 +59,10 @@ public class TestAbandonedObjectPool {
abandonedConfig.setRemoveAbandonedOnBorrow(true);
abandonedConfig.setRemoveAbandonedTimeout(1);
+ assertEquals(TestConstants.ONE_SECOND, abandonedConfig.getRemoveAbandonedTimeoutDuration());
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
+ assertEquals(1, abandonedConfig.getRemoveAbandonedTimeout());
+
pool = new GenericObjectPool<>(
new SimpleFactory(),
new GenericObjectPoolConfig<PooledTestObject>(),
@@ -148,7 +154,7 @@ public class TestAbandonedObjectPool {
public void testAbandonedReturn() throws Exception {
abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnBorrow(true);
- abandonedConfig.setRemoveAbandonedTimeout(1);
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
pool.close(); // Unregister pool created by setup
pool = new GenericObjectPool<>(
new SimpleFactory(200, 0),
@@ -183,7 +189,7 @@ public class TestAbandonedObjectPool {
public void testAbandonedInvalidate() throws Exception {
abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnMaintenance(true);
- abandonedConfig.setRemoveAbandonedTimeout(1);
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
pool.close(); // Unregister pool created by setup
pool = new GenericObjectPool<>(
// destroys take 200 ms
@@ -207,7 +213,7 @@ public class TestAbandonedObjectPool {
public void testDestroyModeAbandoned() throws Exception {
abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnMaintenance(true);
- abandonedConfig.setRemoveAbandonedTimeout(1);
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
pool.close(); // Unregister pool created by setup
pool = new GenericObjectPool<>(
// validate takes 1 second
@@ -241,7 +247,7 @@ public class TestAbandonedObjectPool {
public void testRemoveAbandonedWhileReturning() throws Exception {
abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnMaintenance(true);
- abandonedConfig.setRemoveAbandonedTimeout(1);
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
pool.close(); // Unregister pool created by setup
pool = new GenericObjectPool<>(
// validate takes 1 second
@@ -299,7 +305,7 @@ public class TestAbandonedObjectPool {
public void testStackTrace() throws Exception {
abandonedConfig.setRemoveAbandonedOnMaintenance(true);
abandonedConfig.setLogAbandoned(true);
- abandonedConfig.setRemoveAbandonedTimeout(1);
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final BufferedOutputStream bos = new BufferedOutputStream(baos);
final PrintWriter pw = new PrintWriter(bos);
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestConstants.java b/src/test/java/org/apache/commons/pool2/impl/TestConstants.java
new file mode 100644
index 0000000..14d182f
--- /dev/null
+++ b/src/test/java/org/apache/commons/pool2/impl/TestConstants.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool2.impl;
+
+import java.time.Duration;
+
+public class TestConstants {
+
+ public static final Duration ONE_SECOND = Duration.ofSeconds(1);
+
+}
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
index 9a49a6b..50b3050 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
@@ -112,7 +112,7 @@ public class TestDefaultPooledObjectInfo {
final AbandonedConfig abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnBorrow(true);
- abandonedConfig.setRemoveAbandonedTimeout(1);
+ abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND);
abandonedConfig.setLogAbandoned(true);
try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory(),
new GenericObjectPoolConfig<String>(), abandonedConfig)) {
diff --git a/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java b/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java
index 3db3d1d..4e1b93c 100644
--- a/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/proxy/BaseTestProxiedObjectPool.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.time.Duration;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.ObjectPool;
@@ -39,7 +40,7 @@ import org.junit.jupiter.api.Test;
public abstract class BaseTestProxiedObjectPool {
private static final String DATA1 = "data1";
- private static final int ABANDONED_TIMEOUT_SECS = 3;
+ private static final Duration ABANDONED_TIMEOUT_SECS = Duration.ofSeconds(3);
private ObjectPool<TestObject> pool = null;
private StringWriter log = null;
@@ -130,7 +131,7 @@ public abstract class BaseTestProxiedObjectPool {
obj.setData(DATA1);
// Sleep long enough for the object to be considered abandoned
- Thread.sleep((ABANDONED_TIMEOUT_SECS + 2) * 1000);
+ Thread.sleep(ABANDONED_TIMEOUT_SECS.plusSeconds(2).toMillis());
// Borrow another object to trigger the abandoned object processing
pool.borrowObject();
[commons-pool] 04/05: Add and use java.time.Duration APIs for
AbandonedConfig timeouts instead of using ints as seconds. - Add
GenericObjectPool.getRemoveAbandonedTimeoutDuration()
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 ca34e916613ee21c25ea813cab4f3c37a0cc3031
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 15 12:08:40 2021 -0500
Add and use java.time.Duration APIs for AbandonedConfig timeouts instead
of using ints as seconds.
- Add GenericObjectPool.getRemoveAbandonedTimeoutDuration()
---
src/changes/changes.xml | 5 +++--
.../apache/commons/pool2/impl/GenericObjectPool.java | 20 +++++++++++++++++++-
.../commons/pool2/impl/TestGenericObjectPool.java | 2 ++
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 150db44..ab72916 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -47,8 +47,9 @@ The <action> type attribute can be add,update,fix,remove.
<!-- ADD -->
<action dev="ggregory" type="update" due-to="Dependabot">
Add and use java.time.Duration APIs for AbandonedConfig timeouts instead of using ints for seconds.
- - Add AbandonedConfig.getRemoveAbandonedTimeoutDuration()
- - Add AbandonedConfig.setRemoveAbandonedTimeout(Duration)
+ - Add AbandonedConfig.getRemoveAbandonedTimeoutDuration().
+ - Add AbandonedConfig.setRemoveAbandonedTimeout(Duration).
+ - Add GenericObjectPool.getRemoveAbandonedTimeoutDuration().
</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
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 9991926..f37f614 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
@@ -26,6 +26,7 @@ import org.apache.commons.pool2.SwallowedExceptionListener;
import org.apache.commons.pool2.TrackedUse;
import org.apache.commons.pool2.UsageTracking;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -83,6 +84,8 @@ import java.util.concurrent.atomic.AtomicLong;
public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
implements ObjectPool<T>, GenericObjectPoolMXBean, UsageTracking<T> {
+ private static final Duration DEFAULT_REMOVE_ABANDONED_TIMEOUT = Duration.ofSeconds(Integer.MAX_VALUE);
+
/**
* Creates a new {@code GenericObjectPool} using defaults from
* {@link GenericObjectPoolConfig}.
@@ -290,14 +293,29 @@ public class GenericObjectPool<T> extends BaseGenericObjectPool<T>
*
* @see AbandonedConfig#getRemoveAbandonedTimeout()
* @see AbandonedConfig#getRemoveAbandonedTimeoutDuration()
+ * @deprecated Use {@link #getRemoveAbandonedTimeoutDuration()}.
*/
- @SuppressWarnings("deprecation")
@Override
+ @Deprecated
public int getRemoveAbandonedTimeout() {
final AbandonedConfig ac = this.abandonedConfig;
return ac != null ? ac.getRemoveAbandonedTimeout() : Integer.MAX_VALUE;
}
+ /**
+ * Gets the timeout before which an object will be considered to be
+ * abandoned by this pool.
+ *
+ * @return The abandoned object timeout in seconds if abandoned object
+ * removal is configured for this pool; Integer.MAX_VALUE otherwise.
+ *
+ * @see AbandonedConfig#getRemoveAbandonedTimeout()
+ * @see AbandonedConfig#getRemoveAbandonedTimeoutDuration()
+ */
+ public Duration getRemoveAbandonedTimeoutDuration() {
+ final AbandonedConfig ac = this.abandonedConfig;
+ return ac != null ? ac.getRemoveAbandonedTimeoutDuration() : DEFAULT_REMOVE_ABANDONED_TIMEOUT;
+ }
/**
* Sets the base pool configuration.
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index a1fef27..3250d5e 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -2961,12 +2961,14 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
* Check that a pool that starts an evictor, but is never closed does not
* leave EvictionTimer executor running. Confirmation check is in teardown.
*/
+ @SuppressWarnings("deprecation")
@Test
public void testAbandonedPool() throws Exception {
final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setJmxEnabled(false);
GenericObjectPool<String> abandoned = new GenericObjectPool<>(simpleFactory, config);
abandoned.setTimeBetweenEvictionRunsMillis(100); // Starts evictor
+ assertEquals(abandoned.getRemoveAbandonedTimeout(), abandoned.getRemoveAbandonedTimeoutDuration().getSeconds());
// This is ugly, but forces gc to hit the pool
final WeakReference<GenericObjectPool> ref = new WeakReference<>(abandoned);
[commons-pool] 02/05: Refactor constant. Remove initialization to
default values.
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 650bddc42234d251a43f0813a2c449382b8eee84
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 15 11:05:57 2021 -0500
Refactor constant. Remove initialization to default values.
---
src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java b/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
index 91e2eea..36f7c9a 100644
--- a/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
+++ b/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
@@ -32,10 +32,12 @@ import org.apache.commons.pool2.UsageTracking;
*/
public class AbandonedConfig {
+ private static final Duration DEFAULT_REMOVE_ABANDONED_TIMEOUT = Duration.ofSeconds(300);
+
/**
* Whether or not borrowObject performs abandoned object removal.
*/
- private boolean removeAbandonedOnBorrow = false;
+ private boolean removeAbandonedOnBorrow;
/**
* <p>Flag to remove abandoned objects if they exceed the
@@ -69,7 +71,7 @@ public class AbandonedConfig {
* Whether or not pool maintenance (evictor) performs abandoned object
* removal.
*/
- private boolean removeAbandonedOnMaintenance = false;
+ private boolean removeAbandonedOnMaintenance;
/**
* <p>Flag to remove abandoned objects if they exceed the
@@ -105,7 +107,7 @@ public class AbandonedConfig {
/**
* Timeout before an abandoned object can be removed.
*/
- private Duration removeAbandonedTimeout = Duration.ofSeconds(300);
+ private Duration removeAbandonedTimeout = DEFAULT_REMOVE_ABANDONED_TIMEOUT;
/**
* <p>Timeout in seconds before an abandoned object can be removed.</p>
[commons-pool] 03/05: Bullet-proof test tear-down against NPE when
an actual test fails.
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 35b582ce6d221176dc7c414c79fb73b76a528a72
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 15 11:28:47 2021 -0500
Bullet-proof test tear-down against NPE when an actual test fails.
---
.../pool2/impl/TestAbandonedObjectPool.java | 3 +-
.../pool2/impl/TestGenericKeyedObjectPool.java | 101 +++++++++++++++------
.../commons/pool2/impl/TestGenericObjectPool.java | 5 +-
3 files changed, 80 insertions(+), 29 deletions(-)
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
index 39886aa..030f4e8 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
@@ -71,7 +71,8 @@ public class TestAbandonedObjectPool {
@AfterEach
public void tearDown() throws Exception {
- final String poolName = pool.getJmxName().toString();
+ final ObjectName jmxName = pool.getJmxName();
+ final String poolName = Objects.toString(jmxName, null);
pool.clear();
pool.close();
pool = null;
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 c6141f7..ed8faf2 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -24,6 +24,7 @@ import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.Timer;
@@ -111,7 +112,8 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
@AfterEach
public void tearDown() throws Exception {
super.tearDown();
- final String poolName = gkoPool.getJmxName().toString();
+ final ObjectName jmxName = gkoPool.getJmxName();
+ final String poolName = Objects.toString(jmxName, null);
gkoPool.clear();
gkoPool.close();
gkoPool = null;
@@ -526,37 +528,82 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
final String[] active = new String[500];
final String[] active2 = new String[500];
- for(int i=0;i<500;i++) {
+ for (int i = 0; i < 500; i++) {
active[i] = gkoPool.borrowObject("");
active2[i] = gkoPool.borrowObject("2");
}
- for(int i=0;i<500;i++) {
- gkoPool.returnObject("",active[i]);
- gkoPool.returnObject("2",active2[i]);
+ for (int i = 0; i < 500; i++) {
+ gkoPool.returnObject("", active[i]);
+ gkoPool.returnObject("2", active2[i]);
}
- try { Thread.sleep(1100L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 1000,"Should be less than 1000 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 900,"Should be less than 900 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 800,"Should be less than 800 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 700,"Should be less than 700 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 600,"Should be less than 600 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 500,"Should be less than 500 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 400,"Should be less than 400 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 300,"Should be less than 300 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 200,"Should be less than 200 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertTrue(gkoPool.getNumIdle() < 100,"Should be less than 100 idle, found " + gkoPool.getNumIdle());
- try { Thread.sleep(600L); } catch(final InterruptedException e) { }
- assertEquals(0,gkoPool.getNumIdle(),"Should be zero idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(1100L);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 1000, "Should be less than 1000 idle, found " + gkoPool.getNumIdle());
+ final long sleepMillisPart2 = 600L;
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 900, "Should be less than 900 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 800, "Should be less than 800 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 700, "Should be less than 700 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 600, "Should be less than 600 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 500, "Should be less than 500 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 400, "Should be less than 400 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 300, "Should be less than 300 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 200, "Should be less than 200 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertTrue(gkoPool.getNumIdle() < 100, "Should be less than 100 idle, found " + gkoPool.getNumIdle());
+ try {
+ Thread.sleep(sleepMillisPart2);
+ } catch (final InterruptedException e) {
+ // ignore
+ }
+ assertEquals(0, gkoPool.getNumIdle(), "Should be zero idle, found " + gkoPool.getNumIdle());
}
/**
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index 8381631..a1fef27 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.Timer;
@@ -906,7 +907,9 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
@AfterEach
public void tearDown() throws Exception {
- final String poolName = genericObjectPool.getJmxName().toString();
+ final ObjectName jmxName = genericObjectPool.getJmxName();
+ final String poolName = Objects.toString(jmxName, null);
+
genericObjectPool.clear();
genericObjectPool.close();
genericObjectPool = null;
[commons-pool] 05/05: Switch internals to java.time.Duration. Add
Duration constants based on existing milliseconds constants.
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 91a81e5dc5d7bcfafd5eef52fc7caed8453b3d81
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 15 13:44:08 2021 -0500
Switch internals to java.time.Duration. Add Duration constants based on
existing milliseconds constants.
---
.../commons/pool2/impl/BaseGenericObjectPool.java | 81 ++++-----
.../commons/pool2/impl/BaseObjectPoolConfig.java | 184 +++++++++++++--------
.../apache/commons/pool2/impl/EvictionTimer.java | 15 +-
.../apache/commons/pool2/impl/TestConstants.java | 1 +
.../commons/pool2/impl/TestEvictionTimer.java | 10 +-
.../commons/pool2/impl/TestGenericObjectPool.java | 3 +-
6 files changed, 163 insertions(+), 131 deletions(-)
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 a907014..b8e8cc3 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
@@ -22,6 +22,7 @@ import java.io.Writer;
import java.lang.management.ManagementFactory;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Deque;
import java.util.Iterator;
@@ -66,34 +67,21 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
private static final String EVICTION_POLICY_TYPE_NAME = EvictionPolicy.class.getName();
// Configuration attributes
- private volatile int maxTotal =
- GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL;
- private volatile boolean blockWhenExhausted =
- BaseObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED;
- private volatile long maxWaitMillis =
- BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS;
+ private volatile int maxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL;
+ private volatile boolean blockWhenExhausted = BaseObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED;
+ private volatile Duration maxWait = BaseObjectPoolConfig.DEFAULT_MAX_WAIT;
private volatile boolean lifo = BaseObjectPoolConfig.DEFAULT_LIFO;
private final boolean fairness;
- private volatile boolean testOnCreate =
- BaseObjectPoolConfig.DEFAULT_TEST_ON_CREATE;
- private volatile boolean testOnBorrow =
- BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
- private volatile boolean testOnReturn =
- BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
- private volatile boolean testWhileIdle =
- BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
- private volatile long timeBetweenEvictionRunsMillis =
- BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
- private volatile int numTestsPerEvictionRun =
- BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
- private volatile long minEvictableIdleTimeMillis =
- BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
- private volatile long softMinEvictableIdleTimeMillis =
- BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+ private volatile boolean testOnCreate = BaseObjectPoolConfig.DEFAULT_TEST_ON_CREATE;
+ private volatile boolean testOnBorrow = BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
+ private volatile boolean testOnReturn = BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
+ private volatile boolean testWhileIdle = BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
+ private volatile Duration timeBetweenEvictionRuns = BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS;
+ private volatile int numTestsPerEvictionRun = BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+ private volatile Duration minEvictableIdleTime = BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME;
+ private volatile Duration softMinEvictableIdleTime = BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME;
private volatile EvictionPolicy<T> evictionPolicy;
- private volatile long evictorShutdownTimeoutMillis =
- BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS;
-
+ private volatile Duration evictorShutdownTimeout = BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT;
// Internal (primarily state) attributes
final Object closeLock = new Object();
@@ -259,7 +247,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* @see #setBlockWhenExhausted
*/
public final long getMaxWaitMillis() {
- return maxWaitMillis;
+ return maxWait.toMillis();
}
/**
@@ -277,7 +265,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* @see #setBlockWhenExhausted
*/
public final void setMaxWaitMillis(final long maxWaitMillis) {
- this.maxWaitMillis = maxWaitMillis;
+ this.maxWait = Duration.ofMillis(maxWaitMillis);
}
/**
@@ -475,7 +463,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* @see #setTimeBetweenEvictionRunsMillis
*/
public final long getTimeBetweenEvictionRunsMillis() {
- return timeBetweenEvictionRunsMillis;
+ return timeBetweenEvictionRuns.toMillis();
}
/**
@@ -492,8 +480,8 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
*/
public final void setTimeBetweenEvictionRunsMillis(
final long timeBetweenEvictionRunsMillis) {
- this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- startEvictor(timeBetweenEvictionRunsMillis);
+ this.timeBetweenEvictionRuns = Duration.ofMillis(timeBetweenEvictionRunsMillis);
+ startEvictor(timeBetweenEvictionRuns);
}
/**
@@ -548,7 +536,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* @see #setTimeBetweenEvictionRunsMillis
*/
public final long getMinEvictableIdleTimeMillis() {
- return minEvictableIdleTimeMillis;
+ return minEvictableIdleTime.toMillis();
}
/**
@@ -566,7 +554,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
*/
public final void setMinEvictableIdleTimeMillis(
final long minEvictableIdleTimeMillis) {
- this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ this.minEvictableIdleTime = Duration.ofMillis(minEvictableIdleTimeMillis);
}
/**
@@ -585,7 +573,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* @see #setSoftMinEvictableIdleTimeMillis
*/
public final long getSoftMinEvictableIdleTimeMillis() {
- return softMinEvictableIdleTimeMillis;
+ return softMinEvictableIdleTime.toMillis();
}
/**
@@ -607,7 +595,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
*/
public final void setSoftMinEvictableIdleTimeMillis(
final long softMinEvictableIdleTimeMillis) {
- this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ this.softMinEvictableIdleTime = Duration.ofMillis(softMinEvictableIdleTimeMillis);
}
/**
@@ -707,7 +695,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* the Evictor to shut down.
*/
public final long getEvictorShutdownTimeoutMillis() {
- return evictorShutdownTimeoutMillis;
+ return evictorShutdownTimeout.toMillis();
}
/**
@@ -721,7 +709,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
*/
public final void setEvictorShutdownTimeoutMillis(
final long evictorShutdownTimeoutMillis) {
- this.evictorShutdownTimeoutMillis = evictorShutdownTimeoutMillis;
+ this.evictorShutdownTimeout = Duration.ofMillis(evictorShutdownTimeoutMillis);
}
/**
@@ -781,24 +769,25 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
*
* @param delay time in milliseconds before start and between eviction runs
*/
- final void startEvictor(final long delay) {
+ final void startEvictor(final Duration delay) {
synchronized (evictionLock) {
+ final boolean isPositiverDelay = !delay.isNegative() && !delay.isZero();
if (evictor == null) { // Starting evictor for the first time or after a cancel
- if (delay > 0) { // Starting new evictor
+ if (isPositiverDelay) { // Starting new evictor
evictor = new Evictor();
EvictionTimer.schedule(evictor, delay, delay);
}
} else { // Stop or restart of existing evictor
- if (delay > 0) { // Restart
+ if (isPositiverDelay) { // Restart
synchronized (EvictionTimer.class) { // Ensure no cancel can happen between cancel / schedule calls
- EvictionTimer.cancel(evictor, evictorShutdownTimeoutMillis, TimeUnit.MILLISECONDS, true);
+ EvictionTimer.cancel(evictor, evictorShutdownTimeout, true);
evictor = null;
evictionIterator = null;
evictor = new Evictor();
EvictionTimer.schedule(evictor, delay, delay);
}
} else { // Stopping evictor
- EvictionTimer.cancel(evictor, evictorShutdownTimeoutMillis, TimeUnit.MILLISECONDS, false);
+ EvictionTimer.cancel(evictor, evictorShutdownTimeout, false);
}
}
}
@@ -808,7 +797,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
* Stops the evictor.
*/
void stopEvictor() {
- startEvictor(-1L);
+ startEvictor(Duration.ofMillis(-1L));
}
/**
* Tries to ensure that the configured minimum number of idle instances are
@@ -1375,7 +1364,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
builder.append(", blockWhenExhausted=");
builder.append(blockWhenExhausted);
builder.append(", maxWaitMillis=");
- builder.append(maxWaitMillis);
+ builder.append(maxWait);
builder.append(", lifo=");
builder.append(lifo);
builder.append(", fairness=");
@@ -1389,13 +1378,13 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject {
builder.append(", testWhileIdle=");
builder.append(testWhileIdle);
builder.append(", timeBetweenEvictionRunsMillis=");
- builder.append(timeBetweenEvictionRunsMillis);
+ builder.append(timeBetweenEvictionRuns);
builder.append(", numTestsPerEvictionRun=");
builder.append(numTestsPerEvictionRun);
builder.append(", minEvictableIdleTimeMillis=");
- builder.append(minEvictableIdleTimeMillis);
+ builder.append(minEvictableIdleTime);
builder.append(", softMinEvictableIdleTimeMillis=");
- builder.append(softMinEvictableIdleTimeMillis);
+ builder.append(softMinEvictableIdleTime);
builder.append(", evictionPolicy=");
builder.append(evictionPolicy);
builder.append(", closeLock=");
diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java b/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
index 548fe57..525aede 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
+++ b/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.pool2.impl;
+import java.time.Duration;
+
import org.apache.commons.pool2.BaseObject;
/**
@@ -53,7 +55,15 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
public static final long DEFAULT_MAX_WAIT_MILLIS = -1L;
/**
- * The default value for the {@code minEvictableIdleTimeMillis}
+ * The default value for the {@code maxWait} configuration attribute.
+ * @see GenericObjectPool#getMaxWaitMillis()
+ * @see GenericKeyedObjectPool#getMaxWaitMillis()
+ * @since 2.10.0
+ */
+ public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(DEFAULT_MAX_WAIT_MILLIS);
+
+ /**
+ * The default value for the {@code minEvictableIdleTime}
* configuration attribute.
* @see GenericObjectPool#getMinEvictableIdleTimeMillis()
* @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
@@ -62,7 +72,17 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
1000L * 60L * 30L;
/**
- * The default value for the {@code softMinEvictableIdleTimeMillis}
+ * The default value for the {@code minEvictableIdleTime}
+ * configuration attribute.
+ * @see GenericObjectPool#getMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
+ * @since 2.10.0
+ */
+ public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_TIME =
+ Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+
+ /**
+ * The default value for the {@code softMinEvictableIdleTime}
* configuration attribute.
* @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
* @see GenericKeyedObjectPool#getSoftMinEvictableIdleTimeMillis()
@@ -70,7 +90,17 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
/**
- * The default value for {@code evictorShutdownTimeoutMillis} configuration
+ * The default value for the {@code softMinEvictableIdleTime}
+ * configuration attribute.
+ * @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getSoftMinEvictableIdleTimeMillis()
+ * @since 2.10.0
+ */
+ public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME =
+ Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+
+ /**
+ * The default value for {@code evictorShutdownTimeout} configuration
* attribute.
* @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
* @see GenericKeyedObjectPool#getEvictorShutdownTimeoutMillis()
@@ -79,6 +109,16 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
10L * 1000L;
/**
+ * The default value for {@code evictorShutdownTimeout} configuration
+ * attribute.
+ * @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
+ * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutMillis()
+ * @since 2.10.0
+ */
+ public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT =
+ Duration.ofMillis(DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS);
+
+ /**
* The default value for the {@code numTestsPerEvictionRun} configuration
* attribute.
* @see GenericObjectPool#getNumTestsPerEvictionRun()
@@ -117,7 +157,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
/**
- * The default value for the {@code timeBetweenEvictionRunsMillis}
+ * The default value for the {@code timeBetweenEvictionRuns}
* configuration attribute.
* @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
* @see GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis()
@@ -125,6 +165,15 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
/**
+ * The default value for the {@code timeBetweenEvictionRuns}
+ * configuration attribute.
+ * @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
+ * @see GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis()
+ */
+ public static final Duration DEFAULT_TIME_BETWEEN_EVICTION_RUNS =
+ Duration.ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
+
+ /**
* The default value for the {@code blockWhenExhausted} configuration
* attribute.
* @see GenericObjectPool#getBlockWhenExhausted()
@@ -167,21 +216,17 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
private boolean fairness = DEFAULT_FAIRNESS;
- private long maxWaitMillis = DEFAULT_MAX_WAIT_MILLIS;
+ private Duration maxWaitMillis = DEFAULT_MAX_WAIT;
- private long minEvictableIdleTimeMillis =
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+ private Duration minEvictableIdleTime = DEFAULT_MIN_EVICTABLE_IDLE_TIME;
- private long evictorShutdownTimeoutMillis =
- DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS;
+ private Duration evictorShutdownTimeout = DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT;
- private long softMinEvictableIdleTimeMillis =
- DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+ private Duration softMinEvictableIdleTime = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME;
- private int numTestsPerEvictionRun =
- DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+ private int numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
- private EvictionPolicy<T> evictionPolicy = null; // Only 2.6.0 applications set this
+ private EvictionPolicy<T> evictionPolicy; // Only 2.6.0 applications set this
private String evictionPolicyClassName = DEFAULT_EVICTION_POLICY_CLASS_NAME;
@@ -193,8 +238,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
- private long timeBetweenEvictionRunsMillis =
- DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+ private Duration timeBetweenEvictionRuns = DEFAULT_TIME_BETWEEN_EVICTION_RUNS;
private boolean blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED;
@@ -207,7 +251,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
/**
- * Get the value for the {@code lifo} configuration attribute for pools
+ * Gets the value for the {@code lifo} configuration attribute for pools
* created with this configuration instance.
*
* @return The current setting of {@code lifo} for this configuration
@@ -221,7 +265,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code fairness} configuration attribute for pools
+ * Gets the value for the {@code fairness} configuration attribute for pools
* created with this configuration instance.
*
* @return The current setting of {@code fairness} for this configuration
@@ -235,7 +279,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code lifo} configuration attribute for pools
+ * Sets the value for the {@code lifo} configuration attribute for pools
* created with this configuration instance.
*
* @param lifo The new setting of {@code lifo}
@@ -249,7 +293,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code fairness} configuration attribute for pools
+ * Sets the value for the {@code fairness} configuration attribute for pools
* created with this configuration instance.
*
* @param fairness The new setting of {@code fairness}
@@ -263,7 +307,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code maxWait} configuration attribute for pools
+ * Gets the value for the {@code maxWait} configuration attribute for pools
* created with this configuration instance.
*
* @return The current setting of {@code maxWait} for this
@@ -273,11 +317,11 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
* @see GenericKeyedObjectPool#getMaxWaitMillis()
*/
public long getMaxWaitMillis() {
- return maxWaitMillis;
+ return maxWaitMillis.toMillis();
}
/**
- * Set the value for the {@code maxWait} configuration attribute for pools
+ * Sets the value for the {@code maxWait} configuration attribute for pools
* created with this configuration instance.
*
* @param maxWaitMillis The new setting of {@code maxWaitMillis}
@@ -287,59 +331,59 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
* @see GenericKeyedObjectPool#getMaxWaitMillis()
*/
public void setMaxWaitMillis(final long maxWaitMillis) {
- this.maxWaitMillis = maxWaitMillis;
+ this.maxWaitMillis = Duration.ofMillis(maxWaitMillis);
}
/**
- * Get the value for the {@code minEvictableIdleTimeMillis} configuration
+ * Gets the value for the {@code minEvictableIdleTime} configuration
* attribute for pools created with this configuration instance.
*
- * @return The current setting of {@code minEvictableIdleTimeMillis} for
+ * @return The current setting of {@code minEvictableIdleTime} for
* this configuration instance
*
* @see GenericObjectPool#getMinEvictableIdleTimeMillis()
* @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
*/
public long getMinEvictableIdleTimeMillis() {
- return minEvictableIdleTimeMillis;
+ return minEvictableIdleTime.toMillis();
}
/**
- * Set the value for the {@code minEvictableIdleTimeMillis} configuration
+ * Sets the value for the {@code minEvictableIdleTime} configuration
* attribute for pools created with this configuration instance.
*
* @param minEvictableIdleTimeMillis The new setting of
- * {@code minEvictableIdleTimeMillis} for this configuration instance
+ * {@code minEvictableIdleTime} for this configuration instance
*
* @see GenericObjectPool#getMinEvictableIdleTimeMillis()
* @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
*/
public void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) {
- this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ this.minEvictableIdleTime = Duration.ofMillis(minEvictableIdleTimeMillis);
}
/**
- * Get the value for the {@code softMinEvictableIdleTimeMillis}
+ * Gets the value for the {@code softMinEvictableIdleTime}
* configuration attribute for pools created with this configuration
* instance.
*
- * @return The current setting of {@code softMinEvictableIdleTimeMillis}
+ * @return The current setting of {@code softMinEvictableIdleTime}
* for this configuration instance
*
* @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
* @see GenericKeyedObjectPool#getSoftMinEvictableIdleTimeMillis()
*/
public long getSoftMinEvictableIdleTimeMillis() {
- return softMinEvictableIdleTimeMillis;
+ return softMinEvictableIdleTime.toMillis();
}
/**
- * Set the value for the {@code softMinEvictableIdleTimeMillis}
+ * Sets the value for the {@code softMinEvictableIdleTime}
* configuration attribute for pools created with this configuration
* instance.
*
* @param softMinEvictableIdleTimeMillis The new setting of
- * {@code softMinEvictableIdleTimeMillis} for this configuration
+ * {@code softMinEvictableIdleTime} for this configuration
* instance
*
* @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
@@ -347,11 +391,11 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
*/
public void setSoftMinEvictableIdleTimeMillis(
final long softMinEvictableIdleTimeMillis) {
- this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ this.softMinEvictableIdleTime = Duration.ofMillis(softMinEvictableIdleTimeMillis);
}
/**
- * Get the value for the {@code numTestsPerEvictionRun} configuration
+ * Gets the value for the {@code numTestsPerEvictionRun} configuration
* attribute for pools created with this configuration instance.
*
* @return The current setting of {@code numTestsPerEvictionRun} for this
@@ -365,7 +409,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code numTestsPerEvictionRun} configuration
+ * Sets the value for the {@code numTestsPerEvictionRun} configuration
* attribute for pools created with this configuration instance.
*
* @param numTestsPerEvictionRun The new setting of
@@ -379,25 +423,25 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code evictorShutdownTimeoutMillis} configuration
+ * Gets the value for the {@code evictorShutdownTimeout} configuration
* attribute for pools created with this configuration instance.
*
- * @return The current setting of {@code evictorShutdownTimeoutMillis} for
+ * @return The current setting of {@code evictorShutdownTimeout} for
* this configuration instance
*
* @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
* @see GenericKeyedObjectPool#getEvictorShutdownTimeoutMillis()
*/
public long getEvictorShutdownTimeoutMillis() {
- return evictorShutdownTimeoutMillis;
+ return evictorShutdownTimeout.toMillis();
}
/**
- * Set the value for the {@code evictorShutdownTimeoutMillis} configuration
+ * Sets the value for the {@code evictorShutdownTimeout} configuration
* attribute for pools created with this configuration instance.
*
* @param evictorShutdownTimeoutMillis The new setting of
- * {@code evictorShutdownTimeoutMillis} for this configuration
+ * {@code evictorShutdownTimeout} for this configuration
* instance
*
* @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
@@ -405,11 +449,11 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
*/
public void setEvictorShutdownTimeoutMillis(
final long evictorShutdownTimeoutMillis) {
- this.evictorShutdownTimeoutMillis = evictorShutdownTimeoutMillis;
+ this.evictorShutdownTimeout = Duration.ofMillis(evictorShutdownTimeoutMillis);
}
/**
- * Get the value for the {@code testOnCreate} configuration attribute for
+ * Gets the value for the {@code testOnCreate} configuration attribute for
* pools created with this configuration instance.
*
* @return The current setting of {@code testOnCreate} for this
@@ -425,7 +469,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code testOnCreate} configuration attribute for
+ * Sets the value for the {@code testOnCreate} configuration attribute for
* pools created with this configuration instance.
*
* @param testOnCreate The new setting of {@code testOnCreate}
@@ -441,7 +485,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code testOnBorrow} configuration attribute for
+ * Gets the value for the {@code testOnBorrow} configuration attribute for
* pools created with this configuration instance.
*
* @return The current setting of {@code testOnBorrow} for this
@@ -455,7 +499,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code testOnBorrow} configuration attribute for
+ * Sets the value for the {@code testOnBorrow} configuration attribute for
* pools created with this configuration instance.
*
* @param testOnBorrow The new setting of {@code testOnBorrow}
@@ -469,7 +513,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code testOnReturn} configuration attribute for
+ * Gets the value for the {@code testOnReturn} configuration attribute for
* pools created with this configuration instance.
*
* @return The current setting of {@code testOnReturn} for this
@@ -483,7 +527,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code testOnReturn} configuration attribute for
+ * Sets the value for the {@code testOnReturn} configuration attribute for
* pools created with this configuration instance.
*
* @param testOnReturn The new setting of {@code testOnReturn}
@@ -497,7 +541,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code testWhileIdle} configuration attribute for
+ * Gets the value for the {@code testWhileIdle} configuration attribute for
* pools created with this configuration instance.
*
* @return The current setting of {@code testWhileIdle} for this
@@ -511,7 +555,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code testWhileIdle} configuration attribute for
+ * Sets the value for the {@code testWhileIdle} configuration attribute for
* pools created with this configuration instance.
*
* @param testWhileIdle The new setting of {@code testWhileIdle}
@@ -525,25 +569,25 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code timeBetweenEvictionRunsMillis} configuration
+ * Gets the value for the {@code timeBetweenEvictionRuns} configuration
* attribute for pools created with this configuration instance.
*
- * @return The current setting of {@code timeBetweenEvictionRunsMillis} for
+ * @return The current setting of {@code timeBetweenEvictionRuns} for
* this configuration instance
*
* @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
* @see GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis()
*/
public long getTimeBetweenEvictionRunsMillis() {
- return timeBetweenEvictionRunsMillis;
+ return timeBetweenEvictionRuns.toMillis();
}
/**
- * Set the value for the {@code timeBetweenEvictionRunsMillis} configuration
+ * Sets the value for the {@code timeBetweenEvictionRuns} configuration
* attribute for pools created with this configuration instance.
*
* @param timeBetweenEvictionRunsMillis The new setting of
- * {@code timeBetweenEvictionRunsMillis} for this configuration
+ * {@code timeBetweenEvictionRuns} for this configuration
* instance
*
* @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
@@ -551,11 +595,11 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
*/
public void setTimeBetweenEvictionRunsMillis(
final long timeBetweenEvictionRunsMillis) {
- this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ this.timeBetweenEvictionRuns = Duration.ofMillis(timeBetweenEvictionRunsMillis);
}
/**
- * Get the value for the {@code evictionPolicyClass} configuration
+ * Gets the value for the {@code evictionPolicyClass} configuration
* attribute for pools created with this configuration instance.
*
* @return The current setting of {@code evictionPolicyClass} for this
@@ -570,7 +614,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code evictionPolicyClassName} configuration
+ * Gets the value for the {@code evictionPolicyClassName} configuration
* attribute for pools created with this configuration instance.
*
* @return The current setting of {@code evictionPolicyClassName} for this
@@ -584,7 +628,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code evictionPolicyClass} configuration
+ * Sets the value for the {@code evictionPolicyClass} configuration
* attribute for pools created with this configuration instance.
*
* @param evictionPolicy The new setting of
@@ -599,7 +643,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code evictionPolicyClassName} configuration
+ * Sets the value for the {@code evictionPolicyClassName} configuration
* attribute for pools created with this configuration instance.
*
* @param evictionPolicyClassName The new setting of
@@ -613,7 +657,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Get the value for the {@code blockWhenExhausted} configuration attribute
+ * Gets the value for the {@code blockWhenExhausted} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code blockWhenExhausted} for this
@@ -627,7 +671,7 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
}
/**
- * Set the value for the {@code blockWhenExhausted} configuration attribute
+ * Sets the value for the {@code blockWhenExhausted} configuration attribute
* for pools created with this configuration instance.
*
* @param blockWhenExhausted The new setting of {@code blockWhenExhausted}
@@ -720,10 +764,10 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
builder.append(fairness);
builder.append(", maxWaitMillis=");
builder.append(maxWaitMillis);
- builder.append(", minEvictableIdleTimeMillis=");
- builder.append(minEvictableIdleTimeMillis);
- builder.append(", softMinEvictableIdleTimeMillis=");
- builder.append(softMinEvictableIdleTimeMillis);
+ builder.append(", minEvictableIdleTime=");
+ builder.append(minEvictableIdleTime);
+ builder.append(", softMinEvictableIdleTime=");
+ builder.append(softMinEvictableIdleTime);
builder.append(", numTestsPerEvictionRun=");
builder.append(numTestsPerEvictionRun);
builder.append(", evictionPolicyClassName=");
@@ -736,8 +780,8 @@ public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Clon
builder.append(testOnReturn);
builder.append(", testWhileIdle=");
builder.append(testWhileIdle);
- builder.append(", timeBetweenEvictionRunsMillis=");
- builder.append(timeBetweenEvictionRunsMillis);
+ builder.append(", timeBetweenEvictionRuns=");
+ builder.append(timeBetweenEvictionRuns);
builder.append(", blockWhenExhausted=");
builder.append(blockWhenExhausted);
builder.append(", jmxEnabled=");
diff --git a/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java b/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
index 517e8bb..a12da3b 100644
--- a/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
+++ b/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
@@ -19,6 +19,7 @@ package org.apache.commons.pool2.impl;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.time.Duration;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
@@ -81,16 +82,16 @@ class EvictionTimer {
* @param period Time in milliseconds between executions.
*/
static synchronized void schedule(
- final BaseGenericObjectPool<?>.Evictor task, final long delay, final long period) {
+ final BaseGenericObjectPool<?>.Evictor task, final Duration delay, final Duration period) {
if (null == executor) {
executor = new ScheduledThreadPoolExecutor(1, new EvictorThreadFactory());
executor.setRemoveOnCancelPolicy(true);
- executor.scheduleAtFixedRate(new Reaper(), delay, period, TimeUnit.MILLISECONDS);
+ executor.scheduleAtFixedRate(new Reaper(), delay.toMillis(), period.toMillis(), TimeUnit.MILLISECONDS);
}
final WeakReference<Runnable> ref = new WeakReference<>(task);
final WeakRunner runner = new WeakRunner(ref);
- final ScheduledFuture<?> scheduledFuture =
- executor.scheduleWithFixedDelay(runner, delay, period, TimeUnit.MILLISECONDS);
+ final ScheduledFuture<?> scheduledFuture = executor.scheduleWithFixedDelay(runner, delay.toMillis(),
+ period.toMillis(), TimeUnit.MILLISECONDS);
task.setScheduledFuture(scheduledFuture);
taskMap.put(ref, runner);
}
@@ -102,11 +103,9 @@ class EvictionTimer {
* @param timeout If the associated executor is no longer required, how
* long should this thread wait for the executor to
* terminate?
- * @param unit The units for the specified timeout.
* @param restarting The state of the evictor.
*/
- static synchronized void cancel(
- final BaseGenericObjectPool<?>.Evictor evictor, final long timeout, final TimeUnit unit,
+ static synchronized void cancel(final BaseGenericObjectPool<?>.Evictor evictor, final Duration timeout,
final boolean restarting) {
if (evictor != null) {
evictor.cancel();
@@ -115,7 +114,7 @@ class EvictionTimer {
if (!restarting && executor != null && taskMap.isEmpty()) {
executor.shutdown();
try {
- executor.awaitTermination(timeout, unit);
+ executor.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (final InterruptedException e) {
// Swallow
// Significant API changes would be required to propagate this
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestConstants.java b/src/test/java/org/apache/commons/pool2/impl/TestConstants.java
index 14d182f..1eeb967 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestConstants.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestConstants.java
@@ -22,5 +22,6 @@ import java.time.Duration;
public class TestConstants {
public static final Duration ONE_SECOND = Duration.ofSeconds(1);
+ public static final Duration ONE_MINUTE = Duration.ofMinutes(1);
}
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java b/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java
index ffb00a9..09657ce 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java
@@ -54,7 +54,7 @@ public class TestEvictionTimer {
// Start evictor #1
final BaseGenericObjectPool<String>.Evictor evictor1 = pool.new Evictor();
- EvictionTimer.schedule(evictor1, 60000, 60000);
+ EvictionTimer.schedule(evictor1, TestConstants.ONE_MINUTE, TestConstants.ONE_MINUTE);
// Assert that eviction objects are correctly allocated
// 1 - the evictor timer task is created
@@ -72,7 +72,7 @@ public class TestEvictionTimer {
// Start evictor #2
final BaseGenericObjectPool<String>.Evictor evictor2 = pool.new Evictor();
- EvictionTimer.schedule(evictor2, 60000, 60000);
+ EvictionTimer.schedule(evictor2, TestConstants.ONE_MINUTE, TestConstants.ONE_MINUTE);
// Assert that eviction objects are correctly allocated
// 1 - the evictor timer task is created
@@ -83,8 +83,7 @@ public class TestEvictionTimer {
assertEquals(2, EvictionTimer.getNumTasks());
// Stop evictor #1
- EvictionTimer.cancel(evictor1, BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS,
- TimeUnit.MILLISECONDS, false);
+ EvictionTimer.cancel(evictor1, BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT, false);
// Assert that eviction objects are correctly cleaned
// 1 - the evictor timer task is cancelled
@@ -96,8 +95,7 @@ public class TestEvictionTimer {
assertEquals(1, EvictionTimer.getNumTasks());
// Stop evictor #2
- EvictionTimer.cancel(evictor2, BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS,
- TimeUnit.MILLISECONDS, false);
+ EvictionTimer.cancel(evictor2, BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT, false);
// Assert that eviction objects are correctly cleaned
// 1 - the evictor timer task is cancelled
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index 3250d5e..61f14ba 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -22,6 +22,7 @@ import java.lang.management.ManagementFactory;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.nio.charset.UnsupportedCharsetException;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -2692,7 +2693,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
assertEquals(0,genericObjectPool.getNumIdle(),"Should have 0 idle");
// stop the evictor
- genericObjectPool.startEvictor(0L);
+ genericObjectPool.startEvictor(Duration.ZERO);
}
}