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 b936e5cc14026d25083b238e9c7e22dca3070e9c
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Jun 10 14:12:39 2025 -0400

    Use try-with-resources
---
 .../commons/pool2/impl/TestGenericObjectPool.java   | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java 
b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index e518ed22..477a0b18 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -967,16 +967,17 @@ class TestGenericObjectPool extends TestBaseObjectPool {
     void testAddObjectFastReturn() throws Exception {
         final SimpleFactory simpleFactory = new SimpleFactory();
         simpleFactory.makeLatency = 500;
-        final GenericObjectPool<String> pool = new 
GenericObjectPool<>(simpleFactory);
-        pool.setMaxTotal(1);
-        pool.setBlockWhenExhausted(true);
-        pool.setMaxWait(Duration.ofMillis(1000));
-        // Start a test thread.  The thread will trigger a create, which will 
take 500 ms to complete
-        final TestThread<String> thread = new TestThread<>(pool);
-        final Thread t = new Thread(thread);
-        t.start();
-        Thread.sleep(50); // Wait for the thread to start
-        pool.addObject(); // Should return immediately
+        try (GenericObjectPool<String> pool = new 
GenericObjectPool<>(simpleFactory)) {
+            pool.setMaxTotal(1);
+            pool.setBlockWhenExhausted(true);
+            pool.setMaxWait(Duration.ofMillis(1000));
+            // Start a test thread. The thread will trigger a create, which 
will take 500 ms to complete
+            final TestThread<String> thread = new TestThread<>(pool);
+            final Thread t = new Thread(thread);
+            t.start();
+            Thread.sleep(50); // Wait for the thread to start
+            pool.addObject(); // Should return immediately
+        }
     }
 
     @Test

Reply via email to