messaginghub/pooled-jms

java.util.NoSuchElementException: Pool exhausted

Closed this issue · 2 comments

I've got following exception from pooled-jms code:
java.util.NoSuchElementException: Pool exhausted
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:362)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:265)
at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createJmsPoolConnection(JmsPoolConnectionFactory.java:721)
... 109 common frames omitted

I'm using version 1.0.5 and have configured connectionIdleTimeout/connectionCheckInterval properties on my JmsPoolConnectionFactory.
I suspect that wrong exception is caught in JmsPoolConnectionFactory.createJmsPoolConnection method in line 772.

Please provide a test case that can reproduce the issue

It is a race condition as indicated in comment in JmsPoolConnectionFactory, but I was able to reproduce it with following test.

@Test
public void testCreateConnection() throws Exception {
    cf.setConnectionIdleTimeout(1);
    cf.setConnectionCheckInterval(1);
    for (int i = 0;i< 100000;++i){
        Connection connection = cf.createConnection();
        assertNotNull(connection);
        connection.close();
        Thread.sleep(1);
    }
}