@@ -1012,9 +1012,9 @@ void testAddObjectCanAddToMaxIdle() throws Exception {
10121012 @ RepeatedTest (10 )
10131013 @ Timeout (value = 30 , unit = TimeUnit .SECONDS )
10141014 void testReturnObjectConcurrentCallsRespectsMaxIdleLimit () throws Exception {
1015- final int maxIdleLimit = 5 ;
1015+ final int maxIdleLimit = 4 ;
10161016 // Use more threads than CPU cores to increase contention
1017- final int numThreads = 10 ;
1017+ final int numThreads = 50 ;
10181018
10191019 final GenericObjectPoolConfig <String > config = new GenericObjectPoolConfig <>();
10201020 config .setJmxEnabled (false );
@@ -1034,7 +1034,7 @@ void testReturnObjectConcurrentCallsRespectsMaxIdleLimit() throws Exception {
10341034
10351035 // Use AtomicBoolean with busy-spin for tighter synchronization than CountDownLatch
10361036 final AtomicBoolean startFlag = new AtomicBoolean (false );
1037- final CountDownLatch readyCount = new CountDownLatch (numThreads );
1037+ final CountDownLatch readyCount = new CountDownLatch (1 );
10381038 final CountDownLatch doneLatch = new CountDownLatch (numThreads );
10391039
10401040 final ExecutorService executorService = Executors .newFixedThreadPool (numThreads );
@@ -1044,17 +1044,22 @@ void testReturnObjectConcurrentCallsRespectsMaxIdleLimit() throws Exception {
10441044 executorService .submit (() -> {
10451045 try {
10461046 // Signal ready and busy-spin until start flag is set
1047- readyCount .countDown ();
1047+ readyCount .await ();
10481048 while (!startFlag .get ()) {
10491049 Thread .yield (); // Hint to the JVM that we're spin-waiting
10501050 }
10511051 pool .returnObject (obj );
1052+ }
1053+ catch (InterruptedException e ) {
1054+ throw new RuntimeException (e );
10521055 } finally {
10531056 doneLatch .countDown ();
10541057 }
10551058 });
10561059 }
10571060
1061+ readyCount .countDown ();
1062+
10581063 assertTrue (readyCount .await (10 , TimeUnit .SECONDS ), "Threads failed to start" );
10591064
10601065 // Small delay to ensure all threads are truly in their spin-wait loops
0 commit comments