--- old/src/share/classes/com/sun/jndi/ldap/pool/Pool.java 2011-07-27 17:22:32.426959000 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/pool/Pool.java 2011-07-27 17:22:31.744890800 -0700 @@ -30,7 +30,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import java.util.Set; import java.util.LinkedList; import java.io.PrintStream; @@ -83,17 +82,18 @@ /* * Used for connections cleanup */ - private static final ReferenceQueue queue = new ReferenceQueue(); - private static final Collection weakRefs = - Collections.synchronizedList(new LinkedList()); + private static final ReferenceQueue queue = + new ReferenceQueue<>(); + private static final Collection> weakRefs = + Collections.synchronizedList(new LinkedList>()); final private int maxSize; // max num of identical conn per pool final private int prefSize; // preferred num of identical conn per pool final private int initSize; // initial number of identical conn to create - final private Map map; + final private Map map; public Pool(int initSize, int prefSize, int maxSize) { - map = new WeakHashMap(); + map = new WeakHashMap<>(); this.prefSize = prefSize; this.maxSize = maxSize; this.initSize = initSize; @@ -135,7 +135,8 @@ map.put(id, connsRef); // Create a weak reference to ConnectionsRef - Reference weakRef = new ConnectionsWeakRef(connsRef, queue); + Reference weakRef = + new ConnectionsWeakRef(connsRef, queue); // Keep the weak reference through the element of a linked list weakRefs.add(weakRef); @@ -148,7 +149,7 @@ } private Connections getConnections(Object id) { - ConnectionsRef ref = (ConnectionsRef) map.get(id); + ConnectionsRef ref = map.get(id); return (ref != null) ? ref.getConnections() : null; } @@ -163,11 +164,10 @@ */ public void expire(long threshold) { synchronized (map) { - Collection coll = map.values(); - Iterator iter = coll.iterator(); + Iterator iter = map.values().iterator(); Connections conns; while (iter.hasNext()) { - conns = ((ConnectionsRef) (iter.next())).getConnections(); + conns = iter.next().getConnections(); if (conns.expire(threshold)) { d("expire(): removing ", conns); iter.remove(); @@ -202,7 +202,6 @@ public void showStats(PrintStream out) { - Map.Entry entry; Object id; Connections conns; @@ -212,13 +211,9 @@ out.println("initial pool size: " + initSize); out.println("current pool size: " + map.size()); - Set entries = map.entrySet(); - Iterator iter = entries.iterator(); - - while (iter.hasNext()) { - entry = (Map.Entry) iter.next(); + for (Map.Entry entry : map.entrySet()) { id = entry.getKey(); - conns = ((ConnectionsRef) entry.getValue()).getConnections(); + conns = entry.getValue().getConnections(); out.println(" " + id + ":" + conns.getStats()); }