Skip to content

Commit

Permalink
Update Commons Pool to 2.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jan 29, 2025
1 parent cf47e9f commit ad698a1
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 260 deletions.
2 changes: 1 addition & 1 deletion MERGE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion java/org/apache/tomcat/dbcp/pool2/BaseObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 1 addition & 9 deletions java/org/apache/tomcat/dbcp/pool2/KeyedObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* }
* }</pre>
* <p>
* {@link KeyedObjectPool} implementations <i>may</i> choose to store at most
* {@link KeyedObjectPool} implementations <em>may</em> 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}).
Expand All @@ -66,7 +66,6 @@
* @see KeyedPooledObjectFactory
* @see ObjectPool
* @see org.apache.tomcat.dbcp.pool2.impl.GenericKeyedObjectPool GenericKeyedObjectPool
*
* @since 2.0
*/
public interface KeyedObjectPool<K, V> extends Closeable {
Expand All @@ -78,7 +77,6 @@ public interface KeyedObjectPool<K, V> 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
Expand Down Expand Up @@ -161,9 +159,7 @@ default void addObjects(final K key, final int count) throws Exception {
* </p>
*
* @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
Expand All @@ -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
*
Expand Down Expand Up @@ -280,7 +275,6 @@ default List<K> 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;
Expand All @@ -303,7 +297,6 @@ default List<K> 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
*/
Expand All @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@
* </p>
*
* @see KeyedObjectPool
*
* @param <K> The type of keys managed by this factory.
* @param <V> Type of element managed by this factory.
*
* @since 2.0
*/
public interface KeyedPooledObjectFactory<K, V> {
Expand All @@ -80,7 +78,6 @@ public interface KeyedPooledObjectFactory<K, V> {
*
* @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.
*
Expand All @@ -102,7 +99,6 @@ public interface KeyedPooledObjectFactory<K, V> {
*
* @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.
*
Expand All @@ -117,7 +113,6 @@ public interface KeyedPooledObjectFactory<K, V> {
* @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.
*
Expand All @@ -136,7 +131,6 @@ default void destroyObject(final K key, final PooledObject<V> 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.
*
Expand All @@ -150,7 +144,6 @@ default void destroyObject(final K key, final PooledObject<V> 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.
*
Expand All @@ -163,7 +156,6 @@ default void destroyObject(final K key, final PooledObject<V> 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.
*/
Expand Down
4 changes: 0 additions & 4 deletions java/org/apache/tomcat/dbcp/pool2/ObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
* @see PooledObjectFactory
* @see KeyedObjectPool
* @see BaseObjectPool
*
* @since 2.0
*/
public interface ObjectPool<T> extends Closeable {
Expand Down Expand Up @@ -110,7 +109,6 @@ default void addObjects(final int count) throws Exception {
* </p>
*
* @return an instance from this pool.
*
* @throws IllegalStateException
* after {@link #close close} has been called on this pool.
* @throws Exception
Expand Down Expand Up @@ -176,7 +174,6 @@ default void addObjects(final int count) throws Exception {
* </p>
*
* @param obj a {@link #borrowObject borrowed} instance to be disposed.
*
* @throws Exception if the instance cannot be invalidated
*/
void invalidateObject(T obj) throws Exception;
Expand Down Expand Up @@ -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).
Expand Down
36 changes: 9 additions & 27 deletions java/org/apache/tomcat/dbcp/pool2/PoolUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,8 @@ public String toString() {
* may be invalidated instead of being added to idle capacity.
*
* @param <T> type of objects in the pool
*
*/
private static class ErodingObjectPool<T> implements ObjectPool<T> {
private static final class ErodingObjectPool<T> implements ObjectPool<T> {

/** Underlying object pool */
private final ObjectPool<T> pool;
Expand Down Expand Up @@ -596,7 +595,6 @@ public String toString() {
* as the pool's minIdle setting.
*
* @param <T> type of objects in the pool
*
*/
private static final class ObjectPoolMinIdleTimerTask<T> extends TimerTask {

Expand Down Expand Up @@ -666,7 +664,7 @@ public String toString() {
* A synchronized (thread-safe) KeyedObjectPool backed by the specified
* KeyedObjectPool.
* <p>
* <b>Note:</b> This should not be used on pool implementations that already
* <strong>Note:</strong> 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
Expand Down Expand Up @@ -897,7 +895,7 @@ public String toString() {
* KeyedPooledObjectFactory and synchronizes access to the wrapped factory
* methods.
* <p>
* <b>Note:</b> This should not be used on pool implementations that already
* <strong>Note:</strong> This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library.
* </p>
Expand Down Expand Up @@ -1012,7 +1010,7 @@ public boolean validateObject(final K key, final PooledObject<V> p) {
* A synchronized (thread-safe) ObjectPool backed by the specified
* ObjectPool.
* <p>
* <b>Note:</b> This should not be used on pool implementations that already
* <strong>Note:</strong> 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
Expand All @@ -1021,7 +1019,6 @@ public boolean validateObject(final K key, final PooledObject<V> p) {
* </p>
*
* @param <T> type of objects in the pool
*
*/
private static final class SynchronizedObjectPool<T> implements ObjectPool<T> {

Expand All @@ -1031,7 +1028,7 @@ private static final class SynchronizedObjectPool<T> implements ObjectPool<T> {
*/
private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();

/** the underlying object pool */
/** The underlying object pool */
private final ObjectPool<T> pool;

/**
Expand Down Expand Up @@ -1187,7 +1184,7 @@ public String toString() {
* PooledObjectFactory and synchronizes access to the wrapped factory
* methods.
* <p>
* <b>Note:</b> This should not be used on pool implementations that already
* <strong>Note:</strong> This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library.
* </p>
Expand Down Expand Up @@ -1335,7 +1332,6 @@ static class TimerHolder {
* keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
* @param <K> the type of the pool key
* @param <V> 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
Expand All @@ -1353,10 +1349,7 @@ public static <K, V> Map<K, TimerTask> checkMinIdle(
throw new IllegalArgumentException(MSG_NULL_KEYS);
}
final Map<K, TimerTask> 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;
}

Expand All @@ -1378,7 +1371,6 @@ public static <K, V> Map<K, TimerTask> checkMinIdle(
* keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
* @param <K> the type of the pool key
* @param <V> the type of pool entries
*
* @return the {@link TimerTask} that will periodically check the pools idle
* object count.
* @throws IllegalArgumentException
Expand Down Expand Up @@ -1419,7 +1411,6 @@ public static <K, V> TimerTask checkMinIdle(
* the frequency in milliseconds to check the number of idle objects in a pool,
* see {@link Timer#schedule(TimerTask, long, long)}.
* @param <T> the type of objects in the pool
*
* @return the {@link TimerTask} that will periodically check the pools idle
* object count.
* @throws IllegalArgumentException
Expand Down Expand Up @@ -1471,7 +1462,6 @@ public static void checkRethrow(final Throwable t) {
* count when possible.
* @param <K> the type of the pool key
* @param <V> 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
Expand Down Expand Up @@ -1506,7 +1496,6 @@ public static <K, V> KeyedObjectPool<K, V> erodingPool(final KeyedObjectPool<K,
* shrinks less aggressively.
* @param <K> the type of the pool key
* @param <V> the type of pool entries
*
* @throws IllegalArgumentException
* when {@code keyedPool} is {@code null} or when {@code factor}
* is not positive.
Expand Down Expand Up @@ -1549,7 +1538,6 @@ public static <K, V> KeyedObjectPool<K, V> erodingPool(final KeyedObjectPool<K,
* when true, each key is treated independently.
* @param <K> the type of the pool key
* @param <V> the type of pool entries
*
* @throws IllegalArgumentException
* when {@code keyedPool} is {@code null} or when {@code factor}
* is not positive.
Expand Down Expand Up @@ -1584,7 +1572,6 @@ public static <K, V> KeyedObjectPool<K, V> erodingPool(
* the ObjectPool to be decorated so it shrinks its idle count
* when possible.
* @param <T> 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
Expand Down Expand Up @@ -1617,7 +1604,6 @@ public static <T> ObjectPool<T> erodingPool(final ObjectPool<T> pool) {
* shrinks more aggressively. If 1 &lt; factor then the pool
* shrinks less aggressively.
* @param <T> the type of objects in the pool
*
* @throws IllegalArgumentException
* when {@code pool} is {@code null} or when {@code factor} is
* not positive.
Expand Down Expand Up @@ -1658,7 +1644,6 @@ private static Timer getMinIdleTimer() {
* the number of idle objects to add for each {@code key}.
* @param <K> the type of the pool key
* @param <V> the type of pool entries
*
* @throws Exception
* when {@link KeyedObjectPool#addObject(Object)} fails.
* @throws IllegalArgumentException
Expand Down Expand Up @@ -1689,7 +1674,6 @@ public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool,
* the number of idle objects to add for {@code key}.
* @param <K> the type of the pool key
* @param <V> the type of pool entries
*
* @throws Exception
* when {@link KeyedObjectPool#addObject(Object)} fails.
* @throws IllegalArgumentException
Expand All @@ -1715,7 +1699,6 @@ public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool,
* @param count
* the number of idle objects to add.
* @param <T> the type of objects in the pool
*
* @throws Exception
* when {@link ObjectPool#addObject()} fails.
* @throws IllegalArgumentException
Expand Down Expand Up @@ -1751,7 +1734,7 @@ public static <K, V> KeyedPooledObjectFactory<K, V> synchronizedKeyedPooledFacto
* Returns a synchronized (thread-safe) KeyedObjectPool backed by the
* specified KeyedObjectPool.
* <p>
* <b>Note:</b> This should not be used on pool implementations that already
* <strong>Note:</strong> 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
Expand All @@ -1764,7 +1747,6 @@ public static <K, V> KeyedPooledObjectFactory<K, V> synchronizedKeyedPooledFacto
* KeyedObjectPool.
* @param <K> the type of the pool key
* @param <V> the type of pool entries
*
* @return a synchronized view of the specified KeyedObjectPool.
*/
public static <K, V> KeyedObjectPool<K, V> synchronizedPool(final KeyedObjectPool<K, V> keyedPool) {
Expand All @@ -1784,7 +1766,7 @@ public static <K, V> KeyedObjectPool<K, V> synchronizedPool(final KeyedObjectPoo
* Returns a synchronized (thread-safe) ObjectPool backed by the specified
* ObjectPool.
* <p>
* <b>Note:</b> This should not be used on pool implementations that already
* <strong>Note:</strong> 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
Expand Down
Loading

0 comments on commit ad698a1

Please sign in to comment.