8159822: Non-synchronized access to shared members of com.sun.jndi.ldap.pool.Pool
authorigerasim
Sun, 03 Jul 2016 05:30:47 +0300
changeset 39340 8a08edc76dc4
parent 39339 3a9850ed77e8
child 39341 7ea01bfe5be2
8159822: Non-synchronized access to shared members of com.sun.jndi.ldap.pool.Pool Reviewed-by: coffeys
jdk/src/java.naming/share/classes/com/sun/jndi/ldap/pool/Pool.java
--- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/pool/Pool.java	Sat Jul 02 13:51:20 2016 -0700
+++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/pool/Pool.java	Sun Jul 03 05:30:47 2016 +0300
@@ -118,7 +118,11 @@
         PooledConnectionFactory factory) throws NamingException {
 
         d("get(): ", id);
-        d("size: ", map.size());
+        if (debug) {
+            synchronized (map) {
+                d("size: ", map.size());
+            }
+        }
 
         expungeStaleConnections();
 
@@ -141,10 +145,9 @@
                 // Keep the weak reference through the element of a linked list
                 weakRefs.add(weakRef);
             }
+            d("get(): size after: ", map.size());
         }
 
-        d("get(): size after: ", map.size());
-
         return conns.get(timeout, factory); // get one connection from list
     }
 
@@ -209,19 +212,24 @@
         out.println("maximum pool size: " + maxSize);
         out.println("preferred pool size: " + prefSize);
         out.println("initial pool size: " + initSize);
-        out.println("current pool size: " + map.size());
+
+        synchronized (map) {
+            out.println("current pool size: " + map.size());
 
-        for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
-            id = entry.getKey();
-            conns = entry.getValue().getConnections();
-            out.println("   " + id + ":" + conns.getStats());
+            for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
+                id = entry.getKey();
+                conns = entry.getValue().getConnections();
+                out.println("   " + id + ":" + conns.getStats());
+            }
         }
 
         out.println("====== Pool end =====================");
     }
 
     public String toString() {
-        return super.toString() + " " + map.toString();
+        synchronized (map) {
+            return super.toString() + " " + map.toString();
+        }
     }
 
     private void d(String msg, int i) {