Brian1KB opened a new pull request, #339:
URL: https://github.com/apache/commons-pool/pull/339

   This PR resolves an actively occurring issue with virtual threads that is 
easily reproducible. If you call borrowObject within the GenericObjectPool at a 
high rate in a short period of time with virtual threads, all of the threads 
within the ForkJoinPool for virtual threads will lock up & park, and no virtual 
threads will resume. 
   
   I've already seen there is another Loom related PR that has existed for over 
a year, and I hope that including this demonstration of a production issue will 
hope speed up the process for getting this resolved. The demo will print 
"attempting to acquire", but never "acquired". If you apply my PR, this issue 
is resolved -- in addition, it passes all existing unit tests.
   
   I'm confident that there are other similar issues within the project, though 
I would sure imagine that the maintainers would have a better idea of where to 
look for such problems. Additionally, I'm confident this is not the correct 
branch to PR to, and if I could have I would've filed an issue instead & left 
this part to more competent hands, but the sign up process for the JIRA was too 
complex, and figuring out how to use a mailing list might be more complex for 
me than debugging this issue was.
   
   ```
   package ie.briankenny.main;
   
   import org.apache.commons.pool2.BasePooledObjectFactory;
   import org.apache.commons.pool2.PooledObject;
   import org.apache.commons.pool2.impl.DefaultPooledObject;
   import org.apache.commons.pool2.impl.GenericObjectPool;
   import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
   
   import java.util.concurrent.Executor;
   import java.util.concurrent.Executors;
   
   public class Main {
       public static void main(String[] args) throws Exception {
           GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
   
           poolConfig.setMinIdle(4);
           poolConfig.setMaxIdle(4);
           poolConfig.setMaxTotal(8);
   
           GenericObjectPool<DummyObject> pool = new GenericObjectPool<>(new 
DummyObjectFactory());
   
           Executor executor = Executors.newVirtualThreadPerTaskExecutor();
   
           for (int i = 0; i < 1000; i++) {
               executor.execute(() -> {
                   try {
                       System.out.println("attempting to acquire");
   
                       DummyObject dummyObject = pool.borrowObject();
   
                       System.out.println("acquired");
   
                       pool.returnObject(dummyObject);
                   } catch (Exception e) {
                       throw new RuntimeException(e);
                   }
               });
           }
   
           while (true) {
               Thread.sleep(100);
           }
       }
   }
   
   class DummyObject {
       public DummyObject() throws InterruptedException {
           long sleepTime = (long) (Math.random() * 1000);
   
           Thread.sleep(sleepTime);
       }
   }
   
   class DummyObjectFactory extends BasePooledObjectFactory<DummyObject> {
       @Override
       public DummyObject create() throws Exception {
           return new DummyObject();
       }
   
       @Override
       public PooledObject<DummyObject> wrap(DummyObject obj) {
           return new DefaultPooledObject<>(obj);
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to