This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch POOL_2_X
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit bd7501afcf80427e7489c94c40984a1a98917c64
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Jun 10 14:16:23 2025 -0400

    Use try-with-resources
---
 .../pool2/impl/TestGenericKeyedObjectPool.java     | 58 +++++++++++-----------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java 
b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
index 91e3f97c..3f3e0d5b 100644
--- 
a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ 
b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -1059,7 +1059,8 @@ public class TestGenericKeyedObjectPool extends 
AbstractTestKeyedObjectPool {
         config.setMaxTotalPerKey(1);
         config.setMaxTotal(1);
         config.setMaxWait(Duration.ofMillis(500));
-        final GenericKeyedObjectPool<Integer, Integer> testPool = new 
GenericKeyedObjectPool<>(new KeyedPooledObjectFactory<Integer, Integer>() {
+        try (GenericKeyedObjectPool<Integer, Integer> testPool = new 
GenericKeyedObjectPool<>(new KeyedPooledObjectFactory<Integer, Integer>() {
+
             @Override
             public void activateObject(final Integer key, final 
PooledObject<Integer> p) {
                 // do nothing
@@ -1084,35 +1085,36 @@ public class TestGenericKeyedObjectPool extends 
AbstractTestKeyedObjectPool {
             public boolean validateObject(final Integer key, final 
PooledObject<Integer> p) {
                 return true;
             }
-        }, config);
-        final Integer borrowKey = 10;
-        final int iterations = 100;
-        final ExecutorService executor = Executors.newFixedThreadPool(2);
-        final Thread t = new Thread(() -> {
-            try {
-                for (int i = 0; i < iterations; i++) {
-                    final Integer integer = testPool.borrowObject(borrowKey);
-                    testPool.returnObject(borrowKey, integer);
-                    Thread.sleep(10);
+        }, config)) {
+            final Integer borrowKey = 10;
+            final int iterations = 100;
+            final ExecutorService executor = Executors.newFixedThreadPool(2);
+            final Thread t = new Thread(() -> {
+                try {
+                    for (int i = 0; i < iterations; i++) {
+                        final Integer integer = 
testPool.borrowObject(borrowKey);
+                        testPool.returnObject(borrowKey, integer);
+                        Thread.sleep(10);
+                    }
+                } catch (final Exception e) {
+                    fail(e);
                 }
-            } catch (final Exception e) {
-                fail(e);
-            }
-        });
-        final Thread t2 = new Thread(() -> {
-            try {
-                for (int i = 0; i < iterations; i++) {
-                    testPool.clear(borrowKey);
-                    Thread.sleep(10);
+            });
+            final Thread t2 = new Thread(() -> {
+                try {
+                    for (int i = 0; i < iterations; i++) {
+                        testPool.clear(borrowKey);
+                        Thread.sleep(10);
+                    }
+                } catch (final Exception e) {
+                    fail(e);
                 }
-            } catch (final Exception e) {
-                fail(e);
-            }
-        });
-        final Future<?> f1 = executor.submit(t);
-        final Future<?> f2 = executor.submit(t2);
-        f2.get();
-        f1.get();
+            });
+            final Future<?> f1 = executor.submit(t);
+            final Future<?> f2 = executor.submit(t2);
+            f2.get();
+            f1.get();
+        }
     }
 
     // POOL-259

Reply via email to