Commits

Anonymous committed 7de691a

Submitter: Andres March

CACHE-127 Synchronized copying of the group entry set since
the new HashSet(Collection c) constructor uses the iterator.
This may slow things down but it is better than a
ConcurrentModificationException. We might have to revisit
this code if performance is too adversely impacted.

Comments (0)

Files changed (1)

src/core/java/com/opensymphony/oscache/base/algorithm/AbstractConcurrentReadCache.java

         Set groupEntries = null;
 
         if (memoryCaching && (groups != null)) {
-            groupEntries = (Set) getGroupsForReading().get(groupName);
+            groupEntries = (Set) getGroupForReading(groupName);
         }
 
         if (groupEntries == null) {
             // Not in the map, try the persistence layer
             groupEntries = persistRetrieveGroup(groupName);
-        } else {
-            // We don't want to give them back the internal Set object
-            groupEntries = new HashSet(groupEntries);
-        }
+        } 
 
         return groupEntries;
     }
                     };
         }
     }
-
+    
+    /**
+     * Get ref to group.
+     * CACHE-127 Synchronized copying of the group entry set since
+     * the new HashSet(Collection c) constructor uses the iterator.  
+     * This may slow things down but it is better than a 
+     * ConcurrentModificationException.  We might have to revisit the
+     * code if performance is too adversely impacted.
+     **/
+    protected synchronized final Set getGroupForReading(String groupName) {
+    	Set group = (Set) getGroupsForReading().get(groupName);           
+        return new HashSet(group);
+    }
+    
     /**
      * Get ref to groups.
      * The reference and the cells it