--- old/src/java.naming/share/classes/com/sun/jndi/ldap/pool/Connections.java 2016-12-14 16:02:19.512146102 +0000 +++ new/src/java.naming/share/classes/com/sun/jndi/ldap/pool/Connections.java 2016-12-14 16:02:19.384146096 +0000 @@ -27,7 +27,6 @@ import java.util.ArrayList; // JDK 1.2 import java.util.List; -import java.util.Iterator; import java.lang.ref.Reference; import java.lang.ref.SoftReference; @@ -291,22 +290,27 @@ * @return true if no more connections in list */ synchronized boolean expire(long threshold) { - Iterator iter = conns.iterator(); - ConnectionDesc entry; - while (iter.hasNext()) { - entry = iter.next(); - if (entry.expire(threshold)) { - d("expire(): removing ", entry); - td("Expired ", entry); - - iter.remove(); // remove from pool + List clonedConns; + synchronized(this) { + clonedConns = new ArrayList<>(conns); + } + List expired = new ArrayList<>(); - // Don't need to call notify() because we're - // removing only idle connections. If there were - // idle connections, then there should be no waiters. + for (ConnectionDesc entry : clonedConns) { + d("expire(): ", entry); + if (entry.expire(threshold)) { + expired.add(entry); + td("expire(): Expired ", entry); } } - return conns.isEmpty(); // whether whole list has 'expired' + + synchronized (this) { + conns.removeAll(expired); + // Don't need to call notify() because we're + // removing only idle connections. If there were + // idle connections, then there should be no waiters. + return conns.isEmpty(); // whether whole list has 'expired' + } } /**