This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git
The following commit(s) were added to refs/heads/master by this push:
new 943a3cbf EvictionTimer now restores the current thread's interrupt
flag when catching InterruptedException
943a3cbf is described below
commit 943a3cbf86f7def92b263d42a51742bc1e0d0b34
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jan 28 20:00:53 2026 -0500
EvictionTimer now restores the current thread's interrupt flag when
catching InterruptedException
---
.../apache/commons/pool3/impl/EvictionTimer.java | 1 +
.../commons/pool3/impl/GenericKeyedObjectPool.java | 2 +
.../commons/pool3/impl/GenericObjectPool.java | 2 +
.../pool3/impl/ResilientPooledObjectFactory.java | 2 +
.../java/org/apache/commons/pool3/PoolTest.java | 9 +--
.../pool3/impl/DisconnectingWaiterFactory.java | 1 +
.../impl/TestResilientPooledObjectFactory.java | 74 +++++-----------------
.../commons/pool3/performance/PerformanceTest.java | 6 +-
8 files changed, 31 insertions(+), 66 deletions(-)
diff --git a/src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
b/src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
index 3e5bef80..886b3758 100644
--- a/src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
+++ b/src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
@@ -158,6 +158,7 @@ final class EvictionTimer {
} catch (final InterruptedException e) {
// Swallow
// Significant API changes would be required to propagate this
+ Thread.currentThread().interrupt();
}
executor.setCorePoolSize(0);
executor = null;
diff --git
a/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
index f18efdda..781371b8 100644
--- a/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
@@ -454,6 +454,7 @@ public class GenericKeyedObjectPool<K, T, E extends
Exception> extends BaseGener
p = borrowMaxWaitMillis < 0 ?
objectDeque.getIdleObjects().takeFirst() :
objectDeque.getIdleObjects().pollFirst(borrowMaxWaitMillis,
TimeUnit.MILLISECONDS);
} catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
throw cast(e);
}
}
@@ -778,6 +779,7 @@ public class GenericKeyedObjectPool<K, T, E extends
Exception> extends BaseGener
try {
objectDeque.makeObjectCountLock.wait();
} catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
throw cast(e);
}
}
diff --git a/src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
index 28405293..fcfecd2b 100644
--- a/src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
@@ -314,6 +314,7 @@ public class GenericObjectPool<T, E extends Exception>
extends BaseGenericObject
p = negativeDuration ? idleObjects.takeFirst() :
idleObjects.pollFirst(maxWaitDuration);
} catch (final InterruptedException e) {
// Don't surface exception type of internal locking
mechanism.
+ Thread.currentThread().interrupt();
throw cast(e);
}
}
@@ -543,6 +544,7 @@ public class GenericObjectPool<T, E extends Exception>
extends BaseGenericObject
wait(makeObjectCountLock, remainingWaitDuration);
} catch (final InterruptedException e) {
// Don't surface exception type of internal
locking mechanism.
+ Thread.currentThread().interrupt();
throw cast(e);
}
}
diff --git
a/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
b/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
index b8fabc18..0f1de832 100644
---
a/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
+++
b/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
@@ -88,6 +88,7 @@ public class ResilientPooledObjectFactory<T, E extends
Exception> implements Poo
try {
sleep(delay.toMillis());
} catch (final InterruptedException e) {
+ interrupt();
kill();
}
}
@@ -178,6 +179,7 @@ public class ResilientPooledObjectFactory<T, E extends
Exception> implements Poo
try {
sleep(timeBetweenChecks.toMillis());
} catch (final InterruptedException e) {
+ interrupt();
monitoring = false;
} catch (final Throwable e) {
monitoring = false;
diff --git a/src/test/java/org/apache/commons/pool3/PoolTest.java
b/src/test/java/org/apache/commons/pool3/PoolTest.java
index 5d87c883..0032d43d 100644
--- a/src/test/java/org/apache/commons/pool3/PoolTest.java
+++ b/src/test/java/org/apache/commons/pool3/PoolTest.java
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import java.time.Duration;
+import org.apache.commons.lang3.ThreadUtils;
import org.apache.commons.pool3.impl.DefaultPooledObject;
import org.apache.commons.pool3.impl.GenericObjectPool;
import org.apache.commons.pool3.impl.GenericObjectPoolConfig;
@@ -59,7 +60,7 @@ class PoolTest {
try {
Thread.sleep(VALIDATION_WAIT_IN_MILLIS);
} catch (final InterruptedException e) {
- Thread.interrupted();
+ Thread.currentThread().interrupt();
}
return false;
}
@@ -83,11 +84,7 @@ class PoolTest {
pool.setDurationBetweenEvictionRuns(Duration.ofMillis(EVICTION_PERIOD_IN_MILLIS));
assertEquals(EVICTION_PERIOD_IN_MILLIS,
pool.getDurationBetweenEvictionRuns().toMillis());
pool.addObject();
- try {
- Thread.sleep(EVICTION_PERIOD_IN_MILLIS);
- } catch (final InterruptedException e) {
- Thread.interrupted();
- }
+
ThreadUtils.sleepQuietly(Duration.ofMillis(EVICTION_PERIOD_IN_MILLIS));
}
final Thread[] threads = new Thread[Thread.activeCount()];
Thread.enumerate(threads);
diff --git
a/src/test/java/org/apache/commons/pool3/impl/DisconnectingWaiterFactory.java
b/src/test/java/org/apache/commons/pool3/impl/DisconnectingWaiterFactory.java
index db9b3c81..2fdc7868 100644
---
a/src/test/java/org/apache/commons/pool3/impl/DisconnectingWaiterFactory.java
+++
b/src/test/java/org/apache/commons/pool3/impl/DisconnectingWaiterFactory.java
@@ -69,6 +69,7 @@ public class DisconnectingWaiterFactory<K> extends
WaiterFactory<K> {
try {
Thread.sleep(timeBetweenConnectionChecks.toMillis());
} catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
e.printStackTrace();
}
if (Duration.between(start, Instant.now()).compareTo(maxWait) > 0)
{
diff --git
a/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
b/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
index 49ffa115..242106c0 100644
---
a/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
+++
b/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.util.UUID;
+import org.apache.commons.lang3.ThreadUtils;
import org.apache.commons.pool3.PooledObject;
import org.apache.commons.pool3.PooledObjectFactory;
import org.junit.jupiter.api.Test;
@@ -65,10 +66,7 @@ class TestResilientPooledObjectFactory {
}
if (hang) {
while (!up) {
- try {
- Thread.sleep(1000);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofSeconds(1));
}
}
return null;
@@ -124,10 +122,7 @@ class TestResilientPooledObjectFactory {
}
}.start();
// Wait for the borrower to get in the queue
- try {
- Thread.sleep(50);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(50));
// Crash the base factory
ff.crash();
// Return object will create capacity in the pool
@@ -136,19 +131,13 @@ class TestResilientPooledObjectFactory {
} catch (final Exception e) {
}
// Wait for the adder to run
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(100));
// Adder should be running
assertTrue(rf.isAdderRunning());
// Restart the factory
ff.recover();
// Wait for the adder to succeed
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
// Pool should have no waiters
assertEquals(0, pool.getNumWaiters());
// Adder should still be running because there is a failure in the log
@@ -160,10 +149,7 @@ class TestResilientPooledObjectFactory {
pool.addObject();
}
// Wait for the monitor to run
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
assertTrue(rf.isUp());
// Adder should be stopped
assertFalse(rf.isAdderRunning());
@@ -201,10 +187,7 @@ class TestResilientPooledObjectFactory {
rf.startMonitor();
pool.close();
// Wait for monitor to run so it can kill itself
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
assertFalse(rf.isMonitorRunning());
}
@@ -251,36 +234,24 @@ class TestResilientPooledObjectFactory {
}.start();
// Return borrowed objects - validation will fail
// Wait for the borrowers to get in the queue
- try {
- Thread.sleep(50);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(50));
pool.returnObject(s1);
pool.returnObject(s2);
assertEquals(0, pool.getNumIdle());
assertTrue(pool.getNumWaiters() > 0);
// Wait for the monitor to pick up the failed create which should
happen on
// validation destroy
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
assertFalse(rf.isUp());
// Restart the factory
ff.recover();
// Wait for the adder to succeed
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
// Pool should have no waiters
assertEquals(0, pool.getNumWaiters());
pool.close();
// Wait for monitor to run
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
// Monitor and adder should be stopped by pool close
assertFalse(rf.isAdderRunning());
assertFalse(rf.isMonitorRunning());
@@ -318,11 +289,7 @@ class TestResilientPooledObjectFactory {
}
}.start();
// Wait for the borrower to join wait queue
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
-
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
// Crash the base factory
ff.crash();
// Resilient factory does not know the base factory is down until a
make is
@@ -335,24 +302,16 @@ class TestResilientPooledObjectFactory {
assertEquals(1, pool.getNumWaiters());
// Wait for the monitor to pick up the failed create which should
happen on
// validation destroy
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(100));
assertFalse(rf.isUp());
// Adder should be running, but failing
assertTrue(rf.isAdderRunning());
-
// Pool should have one take waiter
assertEquals(1, pool.getNumWaiters());
-
// Restart the factory
ff.recover();
// Wait for the adder to succeed
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(100));
// Pool should have no waiters
assertTrue(pool.getNumWaiters() == 0);
// Add 5 objects to clear the rf log
@@ -362,10 +321,7 @@ class TestResilientPooledObjectFactory {
pool.addObject();
}
// Wait for monitor to run
- try {
- Thread.sleep(200);
- } catch (final InterruptedException e) {
- }
+ ThreadUtils.sleepQuietly(Duration.ofMillis(200));
// rf should be up now
assertTrue(rf.isUp());
diff --git
a/src/test/java/org/apache/commons/pool3/performance/PerformanceTest.java
b/src/test/java/org/apache/commons/pool3/performance/PerformanceTest.java
index 55c92d8b..ddb9f071 100644
--- a/src/test/java/org/apache/commons/pool3/performance/PerformanceTest.java
+++ b/src/test/java/org/apache/commons/pool3/performance/PerformanceTest.java
@@ -158,6 +158,7 @@ class PerformanceTest {
try {
futures = threadPool.invokeAll(tasks);
} catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
e.printStackTrace();
}
@@ -181,7 +182,10 @@ class PerformanceTest {
TaskStats taskStats = null;
try {
taskStats = future.get();
- } catch (final InterruptedException | ExecutionException e) {
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
+ e.printStackTrace();
+ } catch (final ExecutionException e) {
e.printStackTrace();
}
if (taskStats != null) {