changeset 11867:efa1f84b0458

8159822: Non-synchronized access to shared members of com.sun.jndi.ldap.pool.Pool Reviewed-by: coffeys
author igerasim
date Mon, 04 Jul 2016 16:15:49 +0300
parents 83b4e21a2989
children aaf3403ab820
files src/share/classes/com/sun/jndi/ldap/pool/Pool.java
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/jndi/ldap/pool/Pool.java	Mon Jul 04 16:14:54 2016 +0300
+++ b/src/share/classes/com/sun/jndi/ldap/pool/Pool.java	Mon Jul 04 16:15:49 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());
 
-        for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
-            id = entry.getKey();
-            conns = entry.getValue().getConnections();
-            out.println("   " + id + ":" + conns.getStats());
+        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());
+            }
         }
 
         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) {