I am using Jencks-1.1.3 which uses the Geronimo connector internally.  Sporadically I seem to get the following exception after calling allocateConnection:


        java.util.HashMap$HashIterator.nextEntry(Unknown Source)
        java.util.HashMap$EntryIterator.next(Unknown Source)
        java.util.HashMap$EntryIterator.next(Unknown Source)


The exception usually happens once every 30 minutes in a controlled environment with only two max connections.  Increasing the maximum connection count seems to diminish this exception greatly.  Also, the exception usually happens after filling the pool, waiting a little while, and then hitting the connection a couple more times.


After searching the mailing list I found another person who is having the same type of exception in the same location, but no one has responded to his message.  The name of the message is “NoSuchElementException when using JCAFlow” and can be found here:



I can not find any issue relating to this in JIRA.


(I am not sure if this is the write list to be talking about the code, but…)


After looking at the code:


82 :        if (connectionCount == maxSize) {
83 :        Iterator iterator = pool.entrySet().iterator();
84 :        ManagedConnectionInfo kill = (ManagedConnectionInfo) ((Map.Entry) iterator.next()).getValue();
85 :        iterator.remove();
86 :        ConnectionInfo killInfo = new ConnectionInfo(kill);
87 :        internalReturn(killInfo, ConnectionReturnAction.DESTROY);
88 :        }

I am wondering if there is a possible race condition between the if check on line 82 and the call to iterator.next() on line 84.  In between those two lines all of the connections in the pool could be destroyed? (Note: This is just a wild guess without studying the code closely.) If this is the case then shouldn’t a simply catching of the NoSuchElementException fix this? (I presume that if the pool is empty at this point then everything is okay.)