From ee5fa5efbe25934b83e431e553b733152234fda4 Mon Sep 17 00:00:00 2001
From: Mark Thomas
Date: Wed, 29 Jan 2025 18:03:26 +0000
Subject: [PATCH] Update Commons Pool to 2.12.1
---
MERGE.txt | 2 +-
.../tomcat/dbcp/pool2/BaseObjectPool.java | 1 -
.../tomcat/dbcp/pool2/KeyedObjectPool.java | 10 +--
.../dbcp/pool2/KeyedPooledObjectFactory.java | 8 --
.../apache/tomcat/dbcp/pool2/ObjectPool.java | 4 -
.../apache/tomcat/dbcp/pool2/PoolUtils.java | 36 +++------
.../dbcp/pool2/PooledObjectFactory.java | 8 --
.../tomcat/dbcp/pool2/UsageTracking.java | 1 -
.../dbcp/pool2/impl/AbandonedConfig.java | 2 -
.../pool2/impl/BaseGenericObjectPool.java | 16 +---
.../dbcp/pool2/impl/BaseObjectPoolConfig.java | 32 ++++----
.../pool2/impl/DefaultEvictionPolicy.java | 1 -
.../dbcp/pool2/impl/DefaultPooledObject.java | 2 -
.../pool2/impl/DefaultPooledObjectInfo.java | 3 +-
.../impl/DefaultPooledObjectInfoMBean.java | 2 -
.../tomcat/dbcp/pool2/impl/EvictionTimer.java | 10 +--
.../pool2/impl/GenericKeyedObjectPool.java | 50 +++----------
.../impl/GenericKeyedObjectPoolConfig.java | 29 ++++----
.../dbcp/pool2/impl/GenericObjectPool.java | 73 ++++++++-----------
.../pool2/impl/GenericObjectPoolConfig.java | 24 +++---
.../impl/InterruptibleReentrantLock.java | 2 +-
.../dbcp/pool2/impl/LinkedBlockingDeque.java | 44 ++---------
.../tomcat/dbcp/pool2/impl/PoolImplUtils.java | 7 +-
.../pool2/impl/SoftReferenceObjectPool.java | 5 +-
.../dbcp/pool2/impl/ThrowableCallStack.java | 27 ++++++-
webapps/docs/changelog.xml | 3 +
26 files changed, 142 insertions(+), 260 deletions(-)
diff --git a/MERGE.txt b/MERGE.txt
index 8fc200f810ca..c81293c99168 100644
--- a/MERGE.txt
+++ b/MERGE.txt
@@ -58,7 +58,7 @@ Unused classes removed
Sub-tree
src/main/java/org/apache/commons/pool2
The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
-rel/commons-pool-2.12.0 (2023-09-30)
+rel/commons-pool-2.12.1 (2025-01-27)
DBCP2
No unused code removed
diff --git a/java/org/apache/tomcat/dbcp/pool2/BaseObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/BaseObjectPool.java
index b6108c73a76a..94ed15799760 100644
--- a/java/org/apache/tomcat/dbcp/pool2/BaseObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/BaseObjectPool.java
@@ -49,7 +49,6 @@ public void addObject() throws Exception {
* closed.
*
* @throws IllegalStateException when this pool has been closed.
- *
* @see #isClosed()
*/
protected final void assertOpen() throws IllegalStateException {
diff --git a/java/org/apache/tomcat/dbcp/pool2/KeyedObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/KeyedObjectPool.java
index e0cf3205c459..6d1ba97f4542 100644
--- a/java/org/apache/tomcat/dbcp/pool2/KeyedObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/KeyedObjectPool.java
@@ -49,7 +49,7 @@
* }
* }
*
- * {@link KeyedObjectPool} implementations may choose to store at most
+ * {@link KeyedObjectPool} implementations may choose to store at most
* one instance per key value, or may choose to maintain a pool of instances
* for each key (essentially creating a {@link java.util.Map Map} of
* {@link ObjectPool pools}).
@@ -66,7 +66,6 @@
* @see KeyedPooledObjectFactory
* @see ObjectPool
* @see org.apache.tomcat.dbcp.pool2.impl.GenericKeyedObjectPool GenericKeyedObjectPool
- *
* @since 2.0
*/
public interface KeyedObjectPool extends Closeable {
@@ -78,7 +77,6 @@ public interface KeyedObjectPool extends Closeable {
* "pre-loading" a pool with idle objects (Optional operation).
*
* @param key the key a new instance should be added to
- *
* @throws Exception
* when {@link KeyedPooledObjectFactory#makeObject} fails.
* @throws IllegalStateException
@@ -161,9 +159,7 @@ default void addObjects(final K key, final int count) throws Exception {
*
*
* @param key the key used to obtain the object
- *
* @return an instance from this pool.
- *
* @throws IllegalStateException
* after {@link #close close} has been called on this pool
* @throws Exception
@@ -190,7 +186,6 @@ default void addObjects(final K key, final int count) throws Exception {
* the given {@code key} (optional operation).
*
* @param key the key to clear
- *
* @throws UnsupportedOperationException when this implementation doesn't
* support the operation
*
@@ -280,7 +275,6 @@ default List getKeys() {
*
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
- *
* @throws Exception if the instance cannot be invalidated
*/
void invalidateObject(K key, V obj) throws Exception;
@@ -303,7 +297,6 @@ default List getKeys() {
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
* @param destroyMode destroy activation context provided to the factory
- *
* @throws Exception if the instance cannot be invalidated
* @since 2.9.0
*/
@@ -320,7 +313,6 @@ default void invalidateObject(final K key, final V obj, final DestroyMode destro
*
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
- *
* @throws IllegalStateException
* if an attempt is made to return an object to the pool that
* is in any state other than allocated (i.e. borrowed).
diff --git a/java/org/apache/tomcat/dbcp/pool2/KeyedPooledObjectFactory.java b/java/org/apache/tomcat/dbcp/pool2/KeyedPooledObjectFactory.java
index 35a98423984b..9c0a71c5a9f7 100644
--- a/java/org/apache/tomcat/dbcp/pool2/KeyedPooledObjectFactory.java
+++ b/java/org/apache/tomcat/dbcp/pool2/KeyedPooledObjectFactory.java
@@ -67,10 +67,8 @@
*
*
* @see KeyedObjectPool
- *
* @param The type of keys managed by this factory.
* @param Type of element managed by this factory.
- *
* @since 2.0
*/
public interface KeyedPooledObjectFactory {
@@ -80,7 +78,6 @@ public interface KeyedPooledObjectFactory {
*
* @param key the key used when selecting the object
* @param p a {@code PooledObject} wrapping the instance to be activated
- *
* @throws Exception if there is a problem activating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -102,7 +99,6 @@ public interface KeyedPooledObjectFactory {
*
* @param key the key used when selecting the instance
* @param p a {@code PooledObject} wrapping the instance to be destroyed
- *
* @throws Exception should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -117,7 +113,6 @@ public interface KeyedPooledObjectFactory {
* @param key the key used when selecting the instance
* @param p a {@code PooledObject} wrapping the instance to be destroyed
* @param destroyMode DestroyMode providing context to the factory
- *
* @throws Exception should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -136,7 +131,6 @@ default void destroyObject(final K key, final PooledObject p, final DestroyMo
* wrap it in a {@link PooledObject} to be managed by the pool.
*
* @param key the key used when constructing the object
- *
* @return a {@code PooledObject} wrapping an instance that can
* be served by the pool.
*
@@ -150,7 +144,6 @@ default void destroyObject(final K key, final PooledObject p, final DestroyMo
*
* @param key the key used when selecting the object
* @param p a {@code PooledObject} wrapping the instance to be passivated
- *
* @throws Exception if there is a problem passivating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -163,7 +156,6 @@ default void destroyObject(final K key, final PooledObject p, final DestroyMo
*
* @param key the key used when selecting the object
* @param p a {@code PooledObject} wrapping the instance to be validated
- *
* @return {@code false} if {@code obj} is not valid and should
* be dropped from the pool, {@code true} otherwise.
*/
diff --git a/java/org/apache/tomcat/dbcp/pool2/ObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/ObjectPool.java
index 32b503fc537f..848957f0f0ca 100644
--- a/java/org/apache/tomcat/dbcp/pool2/ObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/ObjectPool.java
@@ -54,7 +54,6 @@
* @see PooledObjectFactory
* @see KeyedObjectPool
* @see BaseObjectPool
- *
* @since 2.0
*/
public interface ObjectPool extends Closeable {
@@ -110,7 +109,6 @@ default void addObjects(final int count) throws Exception {
*
*
* @return an instance from this pool.
- *
* @throws IllegalStateException
* after {@link #close close} has been called on this pool.
* @throws Exception
@@ -176,7 +174,6 @@ default void addObjects(final int count) throws Exception {
*
*
* @param obj a {@link #borrowObject borrowed} instance to be disposed.
- *
* @throws Exception if the instance cannot be invalidated
*/
void invalidateObject(T obj) throws Exception;
@@ -209,7 +206,6 @@ default void invalidateObject(final T obj, final DestroyMode destroyMode) throws
* a related method as defined in an implementation or sub-interface.
*
* @param obj a {@link #borrowObject borrowed} instance to be returned.
- *
* @throws IllegalStateException
* if an attempt is made to return an object to the pool that
* is in any state other than allocated (i.e. borrowed).
diff --git a/java/org/apache/tomcat/dbcp/pool2/PoolUtils.java b/java/org/apache/tomcat/dbcp/pool2/PoolUtils.java
index c8bbbad3311b..73bb4851b516 100644
--- a/java/org/apache/tomcat/dbcp/pool2/PoolUtils.java
+++ b/java/org/apache/tomcat/dbcp/pool2/PoolUtils.java
@@ -326,9 +326,8 @@ public String toString() {
* may be invalidated instead of being added to idle capacity.
*
* @param type of objects in the pool
- *
*/
- private static class ErodingObjectPool implements ObjectPool {
+ private static final class ErodingObjectPool implements ObjectPool {
/** Underlying object pool */
private final ObjectPool pool;
@@ -596,7 +595,6 @@ public String toString() {
* as the pool's minIdle setting.
*
* @param type of objects in the pool
- *
*/
private static final class ObjectPoolMinIdleTimerTask extends TimerTask {
@@ -666,7 +664,7 @@ public String toString() {
* A synchronized (thread-safe) KeyedObjectPool backed by the specified
* KeyedObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
@@ -897,7 +895,7 @@ public String toString() {
* KeyedPooledObjectFactory and synchronizes access to the wrapped factory
* methods.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library.
*
@@ -1012,7 +1010,7 @@ public boolean validateObject(final K key, final PooledObject p) {
* A synchronized (thread-safe) ObjectPool backed by the specified
* ObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
@@ -1021,7 +1019,6 @@ public boolean validateObject(final K key, final PooledObject p) {
*
*
* @param type of objects in the pool
- *
*/
private static final class SynchronizedObjectPool implements ObjectPool {
@@ -1031,7 +1028,7 @@ private static final class SynchronizedObjectPool implements ObjectPool {
*/
private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
- /** the underlying object pool */
+ /** The underlying object pool */
private final ObjectPool pool;
/**
@@ -1187,7 +1184,7 @@ public String toString() {
* PooledObjectFactory and synchronizes access to the wrapped factory
* methods.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library.
*
@@ -1335,7 +1332,6 @@ static class TimerHolder {
* keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
* @param the type of the pool key
* @param the type of pool entries
- *
* @return a {@link Map} of key and {@link TimerTask} pairs that will
* periodically check the pools idle object count.
* @throws IllegalArgumentException
@@ -1353,10 +1349,7 @@ public static Map checkMinIdle(
throw new IllegalArgumentException(MSG_NULL_KEYS);
}
final Map tasks = new HashMap<>(keys.size());
- for (K key : keys) {
- final TimerTask task = checkMinIdle(keyedPool, key, minIdle, periodMillis);
- tasks.put(key, task);
- }
+ keys.forEach(key -> tasks.put(key, checkMinIdle(keyedPool, key, minIdle, periodMillis)));
return tasks;
}
@@ -1378,7 +1371,6 @@ public static Map checkMinIdle(
* keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
* @param the type of the pool key
* @param the type of pool entries
- *
* @return the {@link TimerTask} that will periodically check the pools idle
* object count.
* @throws IllegalArgumentException
@@ -1419,7 +1411,6 @@ public static TimerTask checkMinIdle(
* the frequency in milliseconds to check the number of idle objects in a pool,
* see {@link Timer#schedule(TimerTask, long, long)}.
* @param the type of objects in the pool
- *
* @return the {@link TimerTask} that will periodically check the pools idle
* object count.
* @throws IllegalArgumentException
@@ -1471,7 +1462,6 @@ public static void checkRethrow(final Throwable t) {
* count when possible.
* @param the type of the pool key
* @param the type of pool entries
- *
* @throws IllegalArgumentException
* when {@code keyedPool} is {@code null}.
* @return a pool that adaptively decreases its size when idle objects are
@@ -1506,7 +1496,6 @@ public static KeyedObjectPool erodingPool(final KeyedObjectPool the type of the pool key
* @param the type of pool entries
- *
* @throws IllegalArgumentException
* when {@code keyedPool} is {@code null} or when {@code factor}
* is not positive.
@@ -1549,7 +1538,6 @@ public static KeyedObjectPool erodingPool(final KeyedObjectPool the type of the pool key
* @param the type of pool entries
- *
* @throws IllegalArgumentException
* when {@code keyedPool} is {@code null} or when {@code factor}
* is not positive.
@@ -1584,7 +1572,6 @@ public static KeyedObjectPool erodingPool(
* the ObjectPool to be decorated so it shrinks its idle count
* when possible.
* @param the type of objects in the pool
- *
* @throws IllegalArgumentException
* when {@code pool} is {@code null}.
* @return a pool that adaptively decreases its size when idle objects are
@@ -1617,7 +1604,6 @@ public static ObjectPool erodingPool(final ObjectPool pool) {
* shrinks more aggressively. If 1 < factor then the pool
* shrinks less aggressively.
* @param the type of objects in the pool
- *
* @throws IllegalArgumentException
* when {@code pool} is {@code null} or when {@code factor} is
* not positive.
@@ -1658,7 +1644,6 @@ private static Timer getMinIdleTimer() {
* the number of idle objects to add for each {@code key}.
* @param the type of the pool key
* @param the type of pool entries
- *
* @throws Exception
* when {@link KeyedObjectPool#addObject(Object)} fails.
* @throws IllegalArgumentException
@@ -1689,7 +1674,6 @@ public static void prefill(final KeyedObjectPool keyedPool,
* the number of idle objects to add for {@code key}.
* @param the type of the pool key
* @param the type of pool entries
- *
* @throws Exception
* when {@link KeyedObjectPool#addObject(Object)} fails.
* @throws IllegalArgumentException
@@ -1715,7 +1699,6 @@ public static void prefill(final KeyedObjectPool keyedPool,
* @param count
* the number of idle objects to add.
* @param the type of objects in the pool
- *
* @throws Exception
* when {@link ObjectPool#addObject()} fails.
* @throws IllegalArgumentException
@@ -1751,7 +1734,7 @@ public static KeyedPooledObjectFactory synchronizedKeyedPooledFacto
* Returns a synchronized (thread-safe) KeyedObjectPool backed by the
* specified KeyedObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
@@ -1764,7 +1747,6 @@ public static KeyedPooledObjectFactory synchronizedKeyedPooledFacto
* KeyedObjectPool.
* @param the type of the pool key
* @param the type of pool entries
- *
* @return a synchronized view of the specified KeyedObjectPool.
*/
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) {
@@ -1784,7 +1766,7 @@ public static KeyedObjectPool synchronizedPool(final KeyedObjectPoo
* Returns a synchronized (thread-safe) ObjectPool backed by the specified
* ObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
diff --git a/java/org/apache/tomcat/dbcp/pool2/PooledObjectFactory.java b/java/org/apache/tomcat/dbcp/pool2/PooledObjectFactory.java
index 96d020df82ae..5c5a66203956 100644
--- a/java/org/apache/tomcat/dbcp/pool2/PooledObjectFactory.java
+++ b/java/org/apache/tomcat/dbcp/pool2/PooledObjectFactory.java
@@ -65,9 +65,7 @@
*
*
* @param Type of element managed in this factory.
- *
* @see ObjectPool
- *
* @since 2.0
*/
public interface PooledObjectFactory {
@@ -76,7 +74,6 @@ public interface PooledObjectFactory {
* Reinitializes an instance to be returned by the pool.
*
* @param p a {@code PooledObject} wrapping the instance to be activated
- *
* @throws Exception if there is a problem activating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -98,7 +95,6 @@ public interface PooledObjectFactory {
*
*
* @param p a {@code PooledObject} wrapping the instance to be destroyed
- *
* @throws Exception should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -113,7 +109,6 @@ public interface PooledObjectFactory {
*
* @param p a {@code PooledObject} wrapping the instance to be destroyed
* @param destroyMode DestroyMode providing context to the factory
- *
* @throws Exception should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -132,7 +127,6 @@ default void destroyObject(final PooledObject p, final DestroyMode destroyMod
* {@link PooledObject} to be managed by the pool.
*
* @return a {@code PooledObject} wrapping an instance that can be served by the pool, not null.
- *
* @throws Exception if there is a problem creating a new instance,
* this will be propagated to the code requesting an object.
*/
@@ -142,7 +136,6 @@ default void destroyObject(final PooledObject p, final DestroyMode destroyMod
* Uninitializes an instance to be returned to the idle object pool.
*
* @param p a {@code PooledObject} wrapping the instance to be passivated
- *
* @throws Exception if there is a problem passivating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -154,7 +147,6 @@ default void destroyObject(final PooledObject p, final DestroyMode destroyMod
* Ensures that the instance is safe to be returned by the pool.
*
* @param p a {@code PooledObject} wrapping the instance to be validated
- *
* @return {@code false} if {@code obj} is not valid and should
* be dropped from the pool, {@code true} otherwise.
*/
diff --git a/java/org/apache/tomcat/dbcp/pool2/UsageTracking.java b/java/org/apache/tomcat/dbcp/pool2/UsageTracking.java
index 9d498639c219..6b86754d98c2 100644
--- a/java/org/apache/tomcat/dbcp/pool2/UsageTracking.java
+++ b/java/org/apache/tomcat/dbcp/pool2/UsageTracking.java
@@ -22,7 +22,6 @@
* more informed decisions and reporting to be made regarding abandoned objects.
*
* @param The type of object provided by the pool.
- *
* @since 2.0
*/
public interface UsageTracking {
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/AbandonedConfig.java b/java/org/apache/tomcat/dbcp/pool2/impl/AbandonedConfig.java
index 7f4fc251bbd8..92797c8b4533 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/AbandonedConfig.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/AbandonedConfig.java
@@ -123,7 +123,6 @@ private AbandonedConfig(final AbandonedConfig abandonedConfig) {
*
* @return boolean true if stack trace logging is turned on for abandoned
* objects
- *
*/
public boolean getLogAbandoned() {
return this.logAbandoned;
@@ -240,7 +239,6 @@ public boolean getUseUsageTracking() {
*
* @param logAbandoned true turns on abandoned stack trace logging
* @see #getLogAbandoned()
- *
*/
public void setLogAbandoned(final boolean logAbandoned) {
this.logAbandoned = logAbandoned;
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/BaseGenericObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/impl/BaseGenericObjectPool.java
index 25f30d013538..2e1599fd52f6 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/BaseGenericObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/BaseGenericObjectPool.java
@@ -65,7 +65,7 @@ public abstract class BaseGenericObjectPool extends BaseObject implements Aut
/**
* The idle object eviction iterator. Holds a reference to the idle objects.
*/
- class EvictionIterator implements Iterator> {
+ final class EvictionIterator implements Iterator> {
private final Deque> idleObjects;
private final Iterator> idleObjectIterator;
@@ -117,7 +117,7 @@ public void remove() {
*
* @see GenericKeyedObjectPool#setTimeBetweenEvictionRunsMillis
*/
- class Evictor implements Runnable {
+ final class Evictor implements Runnable {
private ScheduledFuture> scheduledFuture;
@@ -249,7 +249,7 @@ public String toString() {
* Maintains a cache of values for a single metric and reports
* statistics on the cached values.
*/
- private static class StatsStore {
+ private static final class StatsStore {
private static final int NONE = -1;
private final AtomicLong[] values;
@@ -579,7 +579,6 @@ public final long getDestroyedCount() {
* will be run.
*
* @return number of milliseconds to sleep between evictor runs
- *
* @see #setTimeBetweenEvictionRuns
* @since 2.11.0
*/
@@ -603,7 +602,6 @@ public EvictionPolicy getEvictionPolicy() {
* used by this pool.
*
* @return The fully qualified class name of the {@link EvictionPolicy}
- *
* @see #setEvictionPolicyClassName(String)
*/
public final String getEvictionPolicyClassName() {
@@ -935,7 +933,6 @@ public final long getMinEvictableIdleTimeMillis() {
* tested per run.
*
* @return max number of objects to examine during each evictor run
- *
* @see #setNumTestsPerEvictionRun
* @see #setTimeBetweenEvictionRunsMillis
*/
@@ -1150,7 +1147,6 @@ public final boolean getTestOnBorrow() {
* being returned from the {@code borrowObject()} method
*
* @see #setTestOnCreate
- *
* @since 2.2
*/
public final boolean getTestOnCreate() {
@@ -1182,7 +1178,6 @@ public final boolean getTestOnReturn() {
* the pool and destroyed.
*
* @return {@code true} if objects will be validated by the evictor
- *
* @see #setTestWhileIdle
* @see #setTimeBetweenEvictionRunsMillis
*/
@@ -1196,7 +1191,6 @@ public final boolean getTestWhileIdle() {
* will be run.
*
* @return number of milliseconds to sleep between evictor runs
- *
* @see #setTimeBetweenEvictionRuns
* @since 2.10.0
* @deprecated {@link #getDurationBetweenEvictionRuns()}.
@@ -1212,7 +1206,6 @@ public final Duration getTimeBetweenEvictionRuns() {
* will be run.
*
* @return number of milliseconds to sleep between evictor runs
- *
* @see #setTimeBetweenEvictionRunsMillis
* @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
*/
@@ -1333,7 +1326,6 @@ protected void markReturningState(final PooledObject pooledObject) {
* Sets the abandoned object removal configuration.
*
* @param abandonedConfig the new configuration to use. This is used by value.
- *
* @see AbandonedConfig
* @since 2.11.0
*/
@@ -1833,7 +1825,6 @@ public final void setTestOnBorrow(final boolean testOnBorrow) {
* {@code borrowObject()} method
*
* @see #getTestOnCreate
- *
* @since 2.2
*/
public final void setTestOnCreate(final boolean testOnCreate) {
@@ -2078,5 +2069,4 @@ final void updateStatsReturn(final Duration activeTime) {
activeTimes.add(activeTime);
}
-
}
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/BaseObjectPoolConfig.java b/java/org/apache/tomcat/dbcp/pool2/impl/BaseObjectPoolConfig.java
index cd40a8bc5194..38d7aa523e35 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/BaseObjectPoolConfig.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/BaseObjectPoolConfig.java
@@ -33,7 +33,7 @@
public abstract class BaseObjectPoolConfig extends BaseObject implements Cloneable {
/**
- * The default value for the {@code lifo} configuration attribute.
+ * The default value for the {@code lifo} configuration attribute: {@value}.
*
* @see GenericObjectPool#getLifo()
* @see GenericKeyedObjectPool#getLifo()
@@ -41,7 +41,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final boolean DEFAULT_LIFO = true;
/**
- * The default value for the {@code fairness} configuration attribute.
+ * The default value for the {@code fairness} configuration attribute: {@value}.
*
* @see GenericObjectPool#getFairness()
* @see GenericKeyedObjectPool#getFairness()
@@ -49,7 +49,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final boolean DEFAULT_FAIRNESS = false;
/**
- * The default value for the {@code maxWait} configuration attribute.
+ * The default value for the {@code maxWait} configuration attribute: {@value}.
*
* @see GenericObjectPool#getMaxWaitDuration()
* @see GenericKeyedObjectPool#getMaxWaitDuration()
@@ -68,7 +68,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(DEFAULT_MAX_WAIT_MILLIS);
/**
- * The default value for the {@code minEvictableIdleDuration} configuration attribute.
+ * The default value for the {@code minEvictableIdleDuration} configuration attribute: {@value}.
*
* @see GenericObjectPool#getMinEvictableIdleDuration()
* @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
@@ -98,7 +98,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
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.
+ * The default value for the {@code softMinEvictableIdleTime} configuration attribute: {@value}.
*
* @see GenericObjectPool#getSoftMinEvictableIdleDuration()
* @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
@@ -128,7 +128,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
/**
- * The default value for {@code evictorShutdownTimeout} configuration attribute.
+ * The default value for {@code evictorShutdownTimeout} configuration attribute: {@value}.
*
* @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
* @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
@@ -147,7 +147,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT = Duration.ofMillis(DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS);
/**
- * The default value for the {@code numTestsPerEvictionRun} configuration attribute.
+ * The default value for the {@code numTestsPerEvictionRun} configuration attribute: {@value}.
*
* @see GenericObjectPool#getNumTestsPerEvictionRun()
* @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
@@ -155,17 +155,16 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
/**
- * The default value for the {@code testOnCreate} configuration attribute.
+ * The default value for the {@code testOnCreate} configuration attribute: {@value}.
*
* @see GenericObjectPool#getTestOnCreate()
* @see GenericKeyedObjectPool#getTestOnCreate()
- *
* @since 2.2
*/
public static final boolean DEFAULT_TEST_ON_CREATE = false;
/**
- * The default value for the {@code testOnBorrow} configuration attribute.
+ * The default value for the {@code testOnBorrow} configuration attribute: {@value}.
*
* @see GenericObjectPool#getTestOnBorrow()
* @see GenericKeyedObjectPool#getTestOnBorrow()
@@ -173,7 +172,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final boolean DEFAULT_TEST_ON_BORROW = false;
/**
- * The default value for the {@code testOnReturn} configuration attribute.
+ * The default value for the {@code testOnReturn} configuration attribute: {@value}.
*
* @see GenericObjectPool#getTestOnReturn()
* @see GenericKeyedObjectPool#getTestOnReturn()
@@ -181,7 +180,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final boolean DEFAULT_TEST_ON_RETURN = false;
/**
- * The default value for the {@code testWhileIdle} configuration attribute.
+ * The default value for the {@code testWhileIdle} configuration attribute: {@value}.
*
* @see GenericObjectPool#getTestWhileIdle()
* @see GenericKeyedObjectPool#getTestWhileIdle()
@@ -189,7 +188,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
/**
- * The default value for the {@code timeBetweenEvictionRuns} configuration attribute.
+ * The default value for the {@code timeBetweenEvictionRuns} configuration attribute: {@value}.
*
* @see GenericObjectPool#getDurationBetweenEvictionRuns()
* @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
@@ -218,7 +217,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
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.
+ * The default value for the {@code blockWhenExhausted} configuration attribute: {@value}.
*
* @see GenericObjectPool#getBlockWhenExhausted()
* @see GenericKeyedObjectPool#getBlockWhenExhausted()
@@ -226,12 +225,12 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
public static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = true;
/**
- * The default value for enabling JMX for pools created with a configuration instance.
+ * The default value for enabling JMX for pools created with a configuration instance: {@value}.
*/
public static final boolean DEFAULT_JMX_ENABLE = true;
/**
- * The default value for the prefix used to name JMX enabled pools created with a configuration instance.
+ * The default value for the prefix used to name JMX enabled pools created with a configuration instance: {@value}.
*
* @see GenericObjectPool#getJmxName()
* @see GenericKeyedObjectPool#getJmxName()
@@ -420,7 +419,6 @@ public String getJmxNamePrefix() {
* 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 instance
- *
* @see GenericObjectPool#getLifo()
* @see GenericKeyedObjectPool#getLifo()
*/
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultEvictionPolicy.java b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultEvictionPolicy.java
index 0255b6a75c6f..ffe607242e1b 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultEvictionPolicy.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultEvictionPolicy.java
@@ -38,7 +38,6 @@
*
*
* @param the type of objects in the pool.
- *
* @since 2.0
*/
public class DefaultEvictionPolicy implements EvictionPolicy {
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObject.java b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObject.java
index 59c3bdb371fc..a03f2762e583 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObject.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObject.java
@@ -34,7 +34,6 @@
*
*
* @param the type of object in the pool
- *
* @since 2.0
*/
public class DefaultPooledObject implements PooledObject {
@@ -337,5 +336,4 @@ public void use() {
usedBy.fillInStackTrace();
}
-
}
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfo.java b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfo.java
index 2d7b0e35a2db..30854e2fad24 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfo.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfo.java
@@ -24,7 +24,7 @@
import org.apache.tomcat.dbcp.pool2.PooledObject;
/**
- * Implementation of object that is used to provide information on pooled
+ * Implements providing information on pooled
* objects via JMX.
*
* @since 2.0
@@ -65,7 +65,6 @@ public long getLastBorrowTime() {
return pooledObject.getLastBorrowInstant().toEpochMilli();
}
-
@Override
public String getLastBorrowTimeFormatted() {
return getTimeMillisFormatted(getLastBorrowTime());
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfoMBean.java b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfoMBean.java
index fb026de1c847..3e8ad6ea04bc 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfoMBean.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/DefaultPooledObjectInfoMBean.java
@@ -90,7 +90,6 @@ public interface DefaultPooledObjectInfoMBean {
* Gets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.
*
* @return A string representation of the pooled object.
- *
* @see Object#toString()
*/
String getPooledObjectToString();
@@ -99,7 +98,6 @@ public interface DefaultPooledObjectInfoMBean {
* Gets the name of the class of the pooled object.
*
* @return The pooled object's class name.
- *
* @see Class#getName()
*/
String getPooledObjectType();
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java b/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java
index 3c40605c783b..fadc5159b974 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java
@@ -25,7 +25,6 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-
/**
* Provides a shared idle object eviction timer for all pools.
*
@@ -44,12 +43,12 @@
*
* @since 2.0
*/
-class EvictionTimer {
+final class EvictionTimer {
/**
* Thread factory that creates a daemon thread, with the context class loader from this class.
*/
- private static class EvictorThreadFactory implements ThreadFactory {
+ private static final class EvictorThreadFactory implements ThreadFactory {
@Override
public Thread newThread(final Runnable runnable) {
@@ -64,7 +63,7 @@ public Thread newThread(final Runnable runnable) {
* Task that removes references to abandoned tasks and shuts
* down the executor if there are no live tasks left.
*/
- private static class Reaper implements Runnable {
+ private static final class Reaper implements Runnable {
@Override
public void run() {
synchronized (EvictionTimer.class) {
@@ -89,7 +88,7 @@ public void run() {
* no longer reachable, run is no-op.
* @param The kind of Runnable.
*/
- private static class WeakRunner implements Runnable {
+ private static final class WeakRunner implements Runnable {
private final WeakReference ref;
@@ -114,7 +113,6 @@ public void run() {
}
}
-
/** Executor instance */
private static ScheduledThreadPoolExecutor executor; //@GuardedBy("EvictionTimer.class")
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java
index c03ca7792358..07e89b66901d 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java
@@ -83,10 +83,8 @@
*
*
* @see GenericObjectPool
- *
* @param The type of keys maintained by this pool.
* @param Type of element pooled in this pool.
- *
* @since 2.0
*/
public class GenericKeyedObjectPool extends BaseGenericObjectPool
@@ -97,7 +95,7 @@ public class GenericKeyedObjectPool extends BaseGenericObjectPool
*
* @param type of objects in the pool
*/
- private static class ObjectDeque {
+ private static final class ObjectDeque {
private final LinkedBlockingDeque> idleObjects;
@@ -105,7 +103,7 @@ private static class ObjectDeque {
* Number of instances created - number destroyed.
* Invariant: createCount <= maxTotalPerKey
*/
- private final AtomicInteger createCount = new AtomicInteger(0);
+ private final AtomicInteger createCount = new AtomicInteger();
private long makeObjectCount;
private final Object makeObjectCountLock = new Object();
@@ -200,7 +198,6 @@ public String toString() {
private volatile int minIdlePerKey =
GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY;
-
private volatile int maxTotalPerKey =
GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY;
@@ -209,7 +206,7 @@ public String toString() {
private final boolean fairness;
/*
- * My hash of sub-pools (ObjectQueue). The list of keys must be kept
+ * My hash of sub-pools (ObjectQueue). The list of keys must be kept
* in step with {@link #poolKeyList} using {@link #keyLock} to ensure any
* changes to the list of current keys is made in a thread-safe manner.
*/
@@ -218,7 +215,7 @@ public String toString() {
/*
* List of pool keys - used to control eviction order. The list of keys
- * must be kept in step with {@link #poolMap} using {@link #keyLock}
+ * must be kept in step with {@link #poolMap} using {@link #keyLock}
* to ensure any changes to the list of current keys is made in a
* thread-safe manner.
*/
@@ -232,11 +229,10 @@ public String toString() {
* {@link #maxTotal} but there will never be more than {@link #maxTotal}
* created at any one time.
*/
- private final AtomicInteger numTotal = new AtomicInteger(0);
+ private final AtomicInteger numTotal = new AtomicInteger();
private Iterator evictionKeyIterator; // @GuardedBy("evictionLock")
-
private K evictionKey; // @GuardedBy("evictionLock")
/**
@@ -299,7 +295,6 @@ public GenericKeyedObjectPool(final KeyedPooledObjectFactory factory,
*
* @param key The key to associate with the idle object
* @param p The wrapped object to add.
- *
* @throws Exception If the associated factory fails to passivate the object
*/
private void addIdleObject(final K key, final PooledObject p) throws Exception {
@@ -329,7 +324,6 @@ private void addIdleObject(final K key, final PooledObject p) throws Exceptio
*
*
* @param key the key a new instance should be added to
- *
* @throws Exception when {@link KeyedPooledObjectFactory#makeObject}
* fails.
*/
@@ -410,7 +404,6 @@ public T borrowObject(final K key) throws Exception {
* to become available
*
* @return object instance from the keyed pool
- *
* @throws NoSuchElementException if a keyed object instance cannot be
* returned because the pool is exhausted.
*
@@ -520,7 +513,6 @@ public T borrowObject(final K key, final long borrowMaxWaitMillis) throws Except
* on the maximum number of objects either per key or totally.
*
* @param objectDeque The set of objects to check
- *
* @return The number of new objects to create
*/
private int calculateDeficit(final ObjectDeque objectDeque) {
@@ -644,11 +636,9 @@ public void clearOldest() {
// build sorted map of idle objects
final TreeMap, K> map = new TreeMap<>();
- poolMap.forEach((key, value) -> {
- // Each item into the map using the PooledObject object as the
- // key. It then gets sorted based on the idle time
- value.getIdleObjects().forEach(p -> map.put(p, key));
- });
+ // Each item into the map using the PooledObject object as the
+ // key. It then gets sorted based on the idle time
+ poolMap.forEach((key, value) -> value.getIdleObjects().forEach(p -> map.put(p, key)));
// Now iterate created map and kill the first 15% plus one to account
// for zero
@@ -657,9 +647,9 @@ public void clearOldest() {
while (iter.hasNext() && itemsToRemove > 0) {
final Entry, K> entry = iter.next();
- // kind of backwards on naming. In the map, each key is the
+ // kind of backwards on naming. In the map, each key is the
// PooledObject because it has the ordering with the timestamp
- // value. Each value that the key references is the key of the
+ // value. Each value that the key references is the key of the
// list it belongs to.
final K key = entry.getValue();
final PooledObject p = entry.getKey();
@@ -676,7 +666,6 @@ public void clearOldest() {
}
}
-
/**
* Closes the keyed object pool. Once the pool is closed,
* {@link #borrowObject(Object)} will fail with IllegalStateException, but
@@ -716,14 +705,11 @@ public void close() {
}
}
-
/**
* Creates a new pooled object or null.
*
* @param key Key associated with new pooled object.
- *
* @return The new, wrapped pooled object. May return null.
- *
* @throws Exception If the objection creation fails.
*/
private PooledObject create(final K key) throws Exception {
@@ -876,7 +862,6 @@ private void deregister(final K k) {
* @param always Should the object be destroyed even if it is not currently
* in the set of idle objects for the given key
* @param destroyMode DestroyMode context provided to the factory
- *
* @return {@code true} if the object was destroyed, otherwise {@code false}
* @throws Exception If the object destruction failed
*/
@@ -914,7 +899,6 @@ private boolean destroy(final K key, final PooledObject toDestroy, final bool
}
}
-
@Override
void ensureMinIdle() throws Exception {
final int minIdlePerKeySave = getMinIdlePerKey();
@@ -940,7 +924,6 @@ void ensureMinIdle() throws Exception {
*
*
* @param key The key to check for idle objects
- *
* @throws Exception If a new object is required and cannot be created
*/
private void ensureMinIdle(final K key) throws Exception {
@@ -1115,7 +1098,6 @@ public void evict() throws Exception {
}
}
-
/**
* Gets a reference to the factory used to create, destroy and validate
* the objects used by this pool.
@@ -1164,7 +1146,6 @@ public int getMaxIdlePerKey() {
* is said to be exhausted. A negative value indicates no limit.
*
* @return the limit on the number of active instances per key
- *
* @see #setMaxTotalPerKey
*/
@Override
@@ -1186,7 +1167,6 @@ public int getMaxTotalPerKey() {
*
*
* @return minimum size of the each keyed pool
- *
* @see #setTimeBetweenEvictionRunsMillis
*/
@Override
@@ -1307,7 +1287,6 @@ private boolean hasBorrowWaiters() {
*
* @param key pool key
* @param obj instance to invalidate
- *
* @throws Exception if an exception occurs destroying the
* object
* @throws IllegalStateException if obj does not belong to the pool
@@ -1328,7 +1307,6 @@ public void invalidateObject(final K key, final T obj) throws Exception {
* @param key pool key
* @param obj instance to invalidate
* @param destroyMode DestroyMode context provided to factory
- *
* @throws Exception if an exception occurs destroying the
* object
* @throws IllegalStateException if obj does not belong to the pool
@@ -1372,8 +1350,7 @@ public Map> listAllObjects() {
* Registers a key for pool control and ensures that
* {@link #getMinIdlePerKey()} idle instances are created.
*
- * @param key - The key to register for pool control.
- *
+ * @param key The key to register for pool control.
* @throws Exception If the associated factory throws an exception
*/
public void preparePool(final K key) throws Exception {
@@ -1391,7 +1368,6 @@ public void preparePool(final K key) throws Exception {
*
*
* @param k The key to register
- *
* @return The objects currently associated with the given key. If this
* method returns without throwing an exception then it will never
* return null.
@@ -1477,7 +1453,6 @@ private void removeAbandoned(final AbandonedConfig abandonedConfig) {
*
* @param key pool key
* @param obj instance to return to the keyed pool
- *
* @throws IllegalStateException if an object is returned to the pool that
* was not borrowed from it or if an object is
* returned to the pool multiple times
@@ -1623,7 +1598,6 @@ private void reuseCapacity(final int newCapacity) {
* Sets the configuration.
*
* @param conf the new configuration to use. This is used by value.
- *
* @see GenericKeyedObjectPoolConfig
*/
public void setConfig(final GenericKeyedObjectPoolConfig conf) {
@@ -1660,7 +1634,6 @@ public void setMaxIdlePerKey(final int maxIdlePerKey) {
* is said to be exhausted. A negative value indicates no limit.
*
* @param maxTotalPerKey the limit on the number of active instances per key
- *
* @see #getMaxTotalPerKey
*/
public void setMaxTotalPerKey(final int maxTotalPerKey) {
@@ -1681,7 +1654,6 @@ public void setMaxTotalPerKey(final int maxTotalPerKey) {
*
*
* @param minIdlePerKey The minimum size of the each keyed pool
- *
* @see #getMinIdlePerKey()
* @see #getMaxIdlePerKey()
* @see #setDurationBetweenEvictionRuns(Duration)
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPoolConfig.java b/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPoolConfig.java
index 9b4ddd0a609b..14fe7b139cb7 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPoolConfig.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPoolConfig.java
@@ -31,30 +31,33 @@
public class GenericKeyedObjectPoolConfig extends BaseObjectPoolConfig {
/**
- * The default value for the {@code maxTotalPerKey} configuration attribute.
+ * The default value for the {@code maxTotalPerKey} configuration attribute: {@value}.
+ *
* @see GenericKeyedObjectPool#getMaxTotalPerKey()
*/
public static final int DEFAULT_MAX_TOTAL_PER_KEY = 8;
/**
- * The default value for the {@code maxTotal} configuration attribute.
+ * The default value for the {@code maxTotal} configuration attribute: {@value}.
+ *
* @see GenericKeyedObjectPool#getMaxTotal()
*/
public static final int DEFAULT_MAX_TOTAL = -1;
/**
- * The default value for the {@code minIdlePerKey} configuration attribute.
+ * The default value for the {@code minIdlePerKey} configuration attribute: {@value}.
+ *
* @see GenericKeyedObjectPool#getMinIdlePerKey()
*/
public static final int DEFAULT_MIN_IDLE_PER_KEY = 0;
/**
- * The default value for the {@code maxIdlePerKey} configuration attribute.
+ * The default value for the {@code maxIdlePerKey} configuration attribute: {@value}.
+ *
* @see GenericKeyedObjectPool#getMaxIdlePerKey()
*/
public static final int DEFAULT_MAX_IDLE_PER_KEY = 8;
-
private int minIdlePerKey = DEFAULT_MIN_IDLE_PER_KEY;
private int maxIdlePerKey = DEFAULT_MAX_IDLE_PER_KEY;
@@ -80,7 +83,7 @@ public GenericKeyedObjectPoolConfig clone() {
}
/**
- * Get the value for the {@code maxIdlePerKey} configuration attribute
+ * Gets the value for the {@code maxIdlePerKey} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxIdlePerKey} for this
@@ -93,7 +96,7 @@ public int getMaxIdlePerKey() {
}
/**
- * Get the value for the {@code maxTotal} configuration attribute
+ * Gets the value for the {@code maxTotal} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotal} for this
@@ -106,7 +109,7 @@ public int getMaxTotal() {
}
/**
- * Get the value for the {@code maxTotalPerKey} configuration attribute
+ * Gets the value for the {@code maxTotalPerKey} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotalPerKey} for this
@@ -119,7 +122,7 @@ public int getMaxTotalPerKey() {
}
/**
- * Get the value for the {@code minIdlePerKey} configuration attribute
+ * Gets the value for the {@code minIdlePerKey} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code minIdlePerKey} for this
@@ -132,7 +135,7 @@ public int getMinIdlePerKey() {
}
/**
- * Set the value for the {@code maxIdlePerKey} configuration attribute for
+ * Sets the value for the {@code maxIdlePerKey} configuration attribute for
* pools created with this configuration instance.
*
* @param maxIdlePerKey The new setting of {@code maxIdlePerKey}
@@ -145,7 +148,7 @@ public void setMaxIdlePerKey(final int maxIdlePerKey) {
}
/**
- * Set the value for the {@code maxTotal} configuration attribute for
+ * Sets the value for the {@code maxTotal} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotal The new setting of {@code maxTotal}
@@ -158,7 +161,7 @@ public void setMaxTotal(final int maxTotal) {
}
/**
- * Set the value for the {@code maxTotalPerKey} configuration attribute for
+ * Sets the value for the {@code maxTotalPerKey} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotalPerKey The new setting of {@code maxTotalPerKey}
@@ -171,7 +174,7 @@ public void setMaxTotalPerKey(final int maxTotalPerKey) {
}
/**
- * Set the value for the {@code minIdlePerKey} configuration attribute for
+ * Sets the value for the {@code minIdlePerKey} configuration attribute for
* pools created with this configuration instance.
*
* @param minIdlePerKey The new setting of {@code minIdlePerKey}
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java
index 6afb61cde829..98f9819cc073 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java
@@ -74,9 +74,7 @@
*
*
* @see GenericKeyedObjectPool
- *
* @param Type of element pooled in this pool.
- *
* @since 2.0
*/
public class GenericObjectPool extends BaseGenericObjectPool
@@ -87,7 +85,9 @@ public class GenericObjectPool extends BaseGenericObjectPool
"org.apache.commons.pool2:type=GenericObjectPool,name=";
private static void wait(final Object obj, final Duration duration) throws InterruptedException {
- obj.wait(duration.toMillis(), duration.getNano() % 1_000_000);
+ if (!duration.isNegative()) {
+ obj.wait(duration.toMillis(), duration.getNano() % 1_000_000);
+ }
}
private volatile String factoryType;
@@ -185,7 +185,6 @@ public GenericObjectPool(final PooledObjectFactory factory,
* is null, this is a no-op (no exception, but no impact on the pool).
*
* @param p The object to make idle
- *
* @throws Exception If the factory fails to passivate the object
*/
private void addIdleObject(final PooledObject p) throws Exception {
@@ -211,7 +210,6 @@ private void addIdleObject(final PooledObject p) throws Exception {
* is thrown. If there is no factory set (factory == null), an {@code IllegalStateException}
* is thrown.
*
- *
*/
@Override
public void addObject() throws Exception {
@@ -219,7 +217,7 @@ public void addObject() throws Exception {
if (factory == null) {
throw new IllegalStateException("Cannot add objects without a factory.");
}
- addIdleObject(create());
+ addIdleObject(create(getMaxWaitDuration()));
}
/**
@@ -273,9 +271,7 @@ public T borrowObject() throws Exception {
* available instances in request arrival order.
*
*
- * @param borrowMaxWaitDuration The time to wait for an object
- * to become available
- *
+ * @param borrowMaxWaitDuration The time to wait for an object to become available, not null.
* @return object instance from the pool
* @throws NoSuchElementException if an instance cannot be returned
* @throws Exception if an object instance cannot be returned due to an error
@@ -283,38 +279,35 @@ public T borrowObject() throws Exception {
*/
public T borrowObject(final Duration borrowMaxWaitDuration) throws Exception {
assertOpen();
-
+ final Instant startInstant = Instant.now();
+ final boolean negativeDuration = borrowMaxWaitDuration.isNegative();
+ Duration remainingWaitDuration = borrowMaxWaitDuration;
final AbandonedConfig ac = this.abandonedConfig;
- if (ac != null && ac.getRemoveAbandonedOnBorrow() && getNumIdle() < 2 &&
- getNumActive() > getMaxTotal() - 3) {
+ if (ac != null && ac.getRemoveAbandonedOnBorrow() && getNumIdle() < 2 && getNumActive() > getMaxTotal() - 3) {
removeAbandoned(ac);
}
-
PooledObject p = null;
-
// Get local copy of current config so it is consistent for entire
// method execution
final boolean blockWhenExhausted = getBlockWhenExhausted();
-
boolean create;
- final Instant waitTime = Instant.now();
-
while (p == null) {
+ remainingWaitDuration = remainingWaitDuration.minus(durationSince(startInstant));
create = false;
p = idleObjects.pollFirst();
if (p == null) {
- p = create();
+ p = create(remainingWaitDuration);
if (!PooledObject.isNull(p)) {
create = true;
}
}
if (blockWhenExhausted) {
if (PooledObject.isNull(p)) {
- p = borrowMaxWaitDuration.isNegative() ? idleObjects.takeFirst() : idleObjects.pollFirst(borrowMaxWaitDuration);
+ p = negativeDuration ? idleObjects.takeFirst() : idleObjects.pollFirst(remainingWaitDuration);
}
if (PooledObject.isNull(p)) {
throw new NoSuchElementException(appendStats(
- "Timeout waiting for idle object, borrowMaxWaitDuration=" + borrowMaxWaitDuration));
+ "Timeout waiting for idle object, borrowMaxWaitDuration=" + remainingWaitDuration));
}
} else if (PooledObject.isNull(p)) {
throw new NoSuchElementException(appendStats("Pool exhausted"));
@@ -322,7 +315,6 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws Exception {
if (!p.allocate()) {
p = null;
}
-
if (!PooledObject.isNull(p)) {
try {
factory.activateObject(p);
@@ -367,12 +359,14 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws Exception {
}
}
}
-
- updateStatsBorrow(p, Duration.between(waitTime, Instant.now()));
-
+ updateStatsBorrow(p, durationSince(startInstant));
return p.getObject();
}
+ private Duration durationSince(final Instant startInstant) {
+ return Duration.between(startInstant, Instant.now());
+ }
+
/**
* Borrows an object from the pool using the specific waiting time which only
* applies if {@link #getBlockWhenExhausted()} is true.
@@ -415,11 +409,8 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws Exception {
*
* @param borrowMaxWaitMillis The time to wait in milliseconds for an object
* to become available
- *
* @return object instance from the pool
- *
* @throws NoSuchElementException if an instance cannot be returned
- *
* @throws Exception if an object instance cannot be returned due to an
* error
*/
@@ -504,20 +495,19 @@ public void close() {
* If the factory makeObject returns null, this method throws a NullPointerException.
*
*
+ * @param maxWaitDuration The time to wait for an object to become available.
* @return The new wrapped pooled object or null.
* @throws Exception if the object factory's {@code makeObject} fails
*/
- private PooledObject create() throws Exception {
+ private PooledObject create(final Duration maxWaitDuration) throws Exception {
+ final Instant startInstant = Instant.now();
+ Duration remainingWaitDuration = maxWaitDuration.isNegative() ? Duration.ZERO : maxWaitDuration;
int localMaxTotal = getMaxTotal();
// This simplifies the code later in this method
if (localMaxTotal < 0) {
localMaxTotal = Integer.MAX_VALUE;
}
-
final Instant localStartInstant = Instant.now();
- final Duration maxWaitDurationRaw = getMaxWaitDuration();
- final Duration localMaxWaitDuration = maxWaitDurationRaw.isNegative() ? Duration.ZERO : maxWaitDurationRaw;
-
// Flag that indicates if create should:
// - TRUE: call the factory to create an object
// - FALSE: return null
@@ -525,6 +515,8 @@ private PooledObject create() throws Exception {
// call the factory
Boolean create = null;
while (create == null) {
+ // remainingWaitDuration handles spurious wakeup from wait().
+ remainingWaitDuration = remainingWaitDuration.minus(durationSince(startInstant));
synchronized (makeObjectCountLock) {
final long newCreateCount = createCount.incrementAndGet();
if (newCreateCount > localMaxTotal) {
@@ -541,7 +533,7 @@ private PooledObject create() throws Exception {
// bring the pool to capacity. Those calls might also
// fail so wait until they complete and then re-test if
// the pool is at capacity or not.
- wait(makeObjectCountLock, localMaxWaitDuration);
+ wait(makeObjectCountLock, remainingWaitDuration);
}
} else {
// The pool is not at capacity. Create a new object.
@@ -549,10 +541,9 @@ private PooledObject create() throws Exception {
create = Boolean.TRUE;
}
}
-
- // Do not block more if maxWaitTimeMillis is set.
- if (create == null && localMaxWaitDuration.compareTo(Duration.ZERO) > 0 &&
- Duration.between(localStartInstant, Instant.now()).compareTo(localMaxWaitDuration) >= 0) {
+ // Do not block more if remainingWaitDuration > 0.
+ if (create == null && remainingWaitDuration.compareTo(Duration.ZERO) > 0 &&
+ durationSince(localStartInstant).compareTo(remainingWaitDuration) >= 0) {
create = Boolean.FALSE;
}
}
@@ -598,7 +589,6 @@ private PooledObject create() throws Exception {
*
* @param toDestroy The wrapped pooled object to destroy
* @param destroyMode DestroyMode context provided to the factory
- *
* @throws Exception If the factory fails to destroy the pooled object
* cleanly
*/
@@ -637,7 +627,7 @@ private void ensureIdle(final int idleCount, final boolean always) throws Except
}
while (idleObjects.size() < idleCount) {
- final PooledObject p = create();
+ final PooledObject p = create(getMaxWaitDuration());
if (PooledObject.isNull(p)) {
// Can't create objects, no reason to think another call to
// create will work. Give up.
@@ -825,7 +815,6 @@ public String getFactoryType() {
*
* @return the maximum number of "idle" instances that can be held in the
* pool or a negative value if there is no limit
- *
* @see #setMaxIdle
*/
@Override
@@ -845,7 +834,6 @@ public int getMaxIdle() {
*
*
* @return The minimum number of objects.
- *
* @see #setMinIdle(int)
* @see #setMaxIdle(int)
* @see #setDurationBetweenEvictionRuns(Duration)
@@ -1108,7 +1096,6 @@ public void returnObject(final T obj) {
* Sets the base pool configuration.
*
* @param conf the new configuration to use. This is used by value.
- *
* @see GenericObjectPoolConfig
*/
public void setConfig(final GenericObjectPoolConfig conf) {
@@ -1131,7 +1118,6 @@ public void setConfig(final GenericObjectPoolConfig conf) {
* The cap on the number of "idle" instances in the pool. Use a
* negative value to indicate an unlimited number of idle
* instances
- *
* @see #getMaxIdle
*/
public void setMaxIdle(final int maxIdle) {
@@ -1151,7 +1137,6 @@ public void setMaxIdle(final int maxIdle) {
*
* @param minIdle
* The minimum number of objects.
- *
* @see #getMinIdle()
* @see #getMaxIdle()
* @see #getDurationBetweenEvictionRuns()
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java b/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java
index f01c3e732379..ec3271e879c0 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java
@@ -31,24 +31,26 @@
public class GenericObjectPoolConfig extends BaseObjectPoolConfig {
/**
- * The default value for the {@code maxTotal} configuration attribute.
+ * The default value for the {@code maxTotal} configuration attribute: {@value}.
+ *
* @see GenericObjectPool#getMaxTotal()
*/
public static final int DEFAULT_MAX_TOTAL = 8;
/**
- * The default value for the {@code maxIdle} configuration attribute.
+ * The default value for the {@code maxIdle} configuration attribute: {@value}.
+ *
* @see GenericObjectPool#getMaxIdle()
*/
public static final int DEFAULT_MAX_IDLE = 8;
/**
- * The default value for the {@code minIdle} configuration attribute.
+ * The default value for the {@code minIdle} configuration attribute: {@value}.
+ *
* @see GenericObjectPool#getMinIdle()
*/
public static final int DEFAULT_MIN_IDLE = 0;
-
private int maxTotal = DEFAULT_MAX_TOTAL;
private int maxIdle = DEFAULT_MAX_IDLE;
@@ -66,7 +68,7 @@ public GenericObjectPoolConfig clone() {
}
/**
- * Get the value for the {@code maxIdle} configuration attribute
+ * Gets the value for the {@code maxIdle} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxIdle} for this
@@ -78,9 +80,8 @@ public int getMaxIdle() {
return maxIdle;
}
-
/**
- * Get the value for the {@code maxTotal} configuration attribute
+ * Gets the value for the {@code maxTotal} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotal} for this
@@ -93,7 +94,7 @@ public int getMaxTotal() {
}
/**
- * Get the value for the {@code minIdle} configuration attribute
+ * Gets the value for the {@code minIdle} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code minIdle} for this
@@ -105,9 +106,8 @@ public int getMinIdle() {
return minIdle;
}
-
/**
- * Set the value for the {@code maxIdle} configuration attribute for
+ * Sets the value for the {@code maxIdle} configuration attribute for
* pools created with this configuration instance.
*
* @param maxIdle The new setting of {@code maxIdle}
@@ -120,7 +120,7 @@ public void setMaxIdle(final int maxIdle) {
}
/**
- * Set the value for the {@code maxTotal} configuration attribute for
+ * Sets the value for the {@code maxTotal} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotal The new setting of {@code maxTotal}
@@ -133,7 +133,7 @@ public void setMaxTotal(final int maxTotal) {
}
/**
- * Set the value for the {@code minIdle} configuration attribute for
+ * Sets the value for the {@code minIdle} configuration attribute for
* pools created with this configuration instance.
*
* @param minIdle The new setting of {@code minIdle}
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/InterruptibleReentrantLock.java b/java/org/apache/tomcat/dbcp/pool2/impl/InterruptibleReentrantLock.java
index ec06e0101fee..63be6e1678e4 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/InterruptibleReentrantLock.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/InterruptibleReentrantLock.java
@@ -29,7 +29,7 @@
*
* @since 2.0
*/
-class InterruptibleReentrantLock extends ReentrantLock {
+final class InterruptibleReentrantLock extends ReentrantLock {
private static final long serialVersionUID = 1L;
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java b/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java
index 3b95ee9f13f2..7edd10f64edd 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java
@@ -65,7 +65,7 @@
*
* @since 2.0
*/
-class LinkedBlockingDeque extends AbstractQueue
+final class LinkedBlockingDeque extends AbstractQueue
implements Deque, Serializable {
/*
@@ -173,7 +173,6 @@ public E next() {
* iterator.
*
* @param n given node
- *
* @return next node
*/
abstract Node nextNode(Node n);
@@ -222,7 +221,7 @@ private Node succ(Node n) {
}
/** Descending iterator */
- private class DescendingItr extends AbstractItr {
+ private final class DescendingItr extends AbstractItr {
@Override
Node firstNode() { return last; }
@Override
@@ -230,7 +229,7 @@ private class DescendingItr extends AbstractItr {
}
/** Forward iterator */
- private class Itr extends AbstractItr {
+ private final class Itr extends AbstractItr {
@Override
Node firstNode() { return first; }
@Override
@@ -327,7 +326,6 @@ private static final class Node {
this(Integer.MAX_VALUE, fairness);
}
-
// Basic linking and unlinking operations, called only while holding lock
/**
@@ -464,9 +462,7 @@ public Iterator descendingIterator() {
* Drains the queue to the specified collection.
*
* @param c The collection to add the elements to
- *
* @return number of elements added to the collection
- *
* @throws UnsupportedOperationException if the add operation is not
* supported by the specified collection
* @throws ClassCastException if the class of the elements held by this
@@ -483,9 +479,8 @@ public int drainTo(final Collection super E> c) {
* Drains no more than the specified number of elements from the queue to the
* specified collection.
*
- * @param c collection to add the elements to
+ * @param collection collection to add the elements to
* @param maxElements maximum number of elements to remove from the queue
- *
* @return number of elements added to the collection
* @throws UnsupportedOperationException if the add operation is not
* supported by the specified collection
@@ -495,16 +490,16 @@ public int drainTo(final Collection super E> c) {
* @throws NullPointerException if c is null
* @throws IllegalArgumentException if c is this instance
*/
- public int drainTo(final Collection super E> c, final int maxElements) {
- Objects.requireNonNull(c, "c");
- if (c == this) {
+ public int drainTo(final Collection super E> collection, final int maxElements) {
+ Objects.requireNonNull(collection, "collection");
+ if (collection == this) {
throw new IllegalArgumentException();
}
lock.lock();
try {
final int n = Math.min(maxElements, count);
for (int i = 0; i < n; i++) {
- c.add(first.item); // In this order, in case add() throws.
+ collection.add(first.item); // In this order, in case add() throws.
unlinkFirst();
}
return n;
@@ -610,7 +605,6 @@ public Iterator iterator() {
* Links provided element as first element, or returns false if full.
*
* @param e The element to link as the first element.
- *
* @return {@code true} if successful, otherwise {@code false}
*/
private boolean linkFirst(final E e) {
@@ -635,7 +629,6 @@ private boolean linkFirst(final E e) {
* Links provided element as last element, or returns false if full.
*
* @param e The element to link as the last element.
- *
* @return {@code true} if successful, otherwise {@code false}
*/
private boolean linkLast(final E e) {
@@ -669,9 +662,7 @@ public boolean offer(final E e) {
*
* @param e element to link
* @param timeout length of time to wait
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -689,9 +680,7 @@ boolean offer(final E e, final Duration timeout) throws InterruptedException {
* @param e element to link
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -717,9 +706,7 @@ public boolean offerFirst(final E e) {
*
* @param e element to link
* @param timeout length of time to wait
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -748,9 +735,7 @@ public boolean offerFirst(final E e, final Duration timeout) throws InterruptedE
* @param e element to link
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -776,9 +761,7 @@ public boolean offerLast(final E e) {
*
* @param e element to link
* @param timeout length of time to wait
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whist waiting
* for space
@@ -807,9 +790,7 @@ boolean offerLast(final E e, final Duration timeout) throws InterruptedException
* @param e element to link
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whist waiting
* for space
@@ -857,7 +838,6 @@ public E poll() {
* This method is equivalent to {@link #pollFirst(long, TimeUnit)}.
*
* @param timeout length of time to wait
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -873,7 +853,6 @@ E poll(final Duration timeout) throws InterruptedException {
*
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -896,7 +875,6 @@ public E pollFirst() {
* to do so if the queue is empty.
*
* @param timeout length of time to wait
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -923,7 +901,6 @@ E pollFirst(final Duration timeout) throws InterruptedException {
*
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -946,7 +923,6 @@ public E pollLast() {
* to do so if the queue is empty.
*
* @param timeout length of time to wait
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -974,7 +950,6 @@ public E pollLast(final Duration timeout)
*
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -1002,7 +977,6 @@ public void push(final E e) {
*
*
* @param e element to link
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -1016,7 +990,6 @@ public void put(final E e) throws InterruptedException {
* is space to do so if the queue is full.
*
* @param e element to link
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -1038,7 +1011,6 @@ public void putFirst(final E e) throws InterruptedException {
* is space to do so if the queue is full.
*
* @param e element to link
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java b/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java
index eaea8ca88e8b..f552f38bc998 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java
@@ -32,13 +32,12 @@
*
* @since 2.0
*/
-class PoolImplUtils {
+final class PoolImplUtils {
/**
* Identifies the concrete type of object that an object factory creates.
*
* @param factoryClass The factory to examine
- *
* @return the type of object the factory creates
*/
@SuppressWarnings("rawtypes")
@@ -73,7 +72,6 @@ static Class> getFactoryType(final Class extends PooledObjectFactory> factor
* @param type The interface that defines a generic type
* @param clazz The class that implements the interface with a concrete type
* @param The interface type
- *
* @return concrete type used by the implementation
*/
private static Object getGenericType(final Class type, final Class extends T> clazz) {
@@ -135,7 +133,6 @@ private static ParameterizedType getParameterizedType(final Class type, f
*
* @param clazz defining class
* @param argType the type argument of interest
- *
* @return An instance of {@link Class} representing the type used by the type parameter or an instance of
* {@link Integer} representing the index for the type in the definition of the defining class
*/
@@ -227,7 +224,7 @@ static ChronoUnit toChronoUnit(final TimeUnit timeUnit) {
* @return a Duration.
*/
static Duration toDuration(final long amount, final TimeUnit timeUnit) {
- return Duration.of(amount, PoolImplUtils.toChronoUnit(timeUnit));
+ return Duration.of(amount, toChronoUnit(timeUnit));
}
}
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java
index c59874aed9bc..c39b105e9b86 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java
@@ -58,7 +58,6 @@ public class SoftReferenceObjectPool extends BaseObjectPool {
/** Total number of instances that have been destroyed */
private long destroyCount; // @GuardedBy("this")
-
/** Total number of instances that have been created */
private long createCount; // @GuardedBy("this")
@@ -267,7 +266,6 @@ public void close() {
* references pools.
*
* @param toDestroy PooledSoftReference to destroy
- *
* @throws Exception If an error occurs while trying to destroy the object
*/
private void destroy(final PooledSoftReference toDestroy) throws Exception {
@@ -348,7 +346,8 @@ private void pruneClearedReferences() {
// Remove wrappers for enqueued references from idle and allReferences lists
removeClearedReferences(idleReferences.iterator());
removeClearedReferences(allReferences.iterator());
- while (refQueue.poll() != null) { // NOPMD
+ while (refQueue.poll() != null) {
+ // loop until null
}
}
diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/ThrowableCallStack.java b/java/org/apache/tomcat/dbcp/pool2/impl/ThrowableCallStack.java
index 5c9f89a71bc5..18592b20502e 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/ThrowableCallStack.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/ThrowableCallStack.java
@@ -19,6 +19,7 @@
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.time.Instant;
/**
* CallStack strategy that uses the stack trace from a {@link Throwable}. This
@@ -33,13 +34,32 @@ public class ThrowableCallStack implements CallStack {
/**
* A snapshot of a throwable.
*/
- private static class Snapshot extends Throwable {
+ private static final class Snapshot extends Throwable {
+
private static final long serialVersionUID = 1L;
- private final long timestampMillis = System.currentTimeMillis();
+ private final Instant timestamp;
+
+ /**
+ * Constructs a new instance with its message set to the now instant.
+ */
+ Snapshot() {
+ this(Instant.now());
+ }
+
+ /**
+ * Constructs a new instance and use the timestamp as the message with using {@link DateTimeFormatter#ISO_INSTANT} for more precision.
+ *
+ * @param timestamp normally the now instant.
+ */
+ private Snapshot(final Instant timestamp) {
+ super(timestamp.toString());
+ this.timestamp = timestamp;
+ }
}
private final String messageFormat;
+ // We keep the SimpleDateFormat for backward compatibility instead of a DateTimeFormatter.
//@GuardedBy("dateFormat")
private final DateFormat dateFormat;
@@ -77,7 +97,8 @@ public synchronized boolean printStackTrace(final PrintWriter writer) {
message = messageFormat;
} else {
synchronized (dateFormat) {
- message = dateFormat.format(Long.valueOf(snapshotRef.timestampMillis));
+ // The throwable message is in {@link DateTimeFormatter#ISO_INSTANT} format for more precision.
+ message = dateFormat.format(Long.valueOf(snapshotRef.timestamp.toEpochMilli()));
}
}
writer.println(message);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5a4d7c6e4034..ce9c0519b808 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -328,6 +328,9 @@
Update the packaged version of the Tomcat Migration Tool for Jakarta EE
to 1.0.9. (markt)
+
+ Update the internal fork of Commons Pool to 2.12.1. (markt)
+