Anonymous avatar Anonymous committed 5bf0aa1

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.