Skip to content

Commit 3dbd337

Browse files
dmercurialidennis.mercuriali
andauthored
avoid concurrent mod in eviction (#203)
Co-authored-by: dennis.mercuriali <dennis.mercuriali@diennea.com>
1 parent 054f3d2 commit 3dbd337

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

blazingcache-core/src/main/java/blazingcache/client/CacheClient.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -719,18 +719,15 @@ public void accept(EntryHandle t) {
719719
}
720720
};
721721

722-
try {
723-
cache.values().stream().sorted((EntryHandle o1, EntryHandle o2) -> {
724-
long diff = o1.getLastGetTime() - o2.getLastGetTime();
725-
if (diff == 0) {
726-
return 0;
727-
}
728-
return diff > 0 ? 1 : -1;
729-
}).forEachOrdered(accumulator);
730-
} catch (Exception dataChangedDuringSort) {
731-
LOGGER.severe("dataChangedDuringSort: " + dataChangedDuringSort);
732-
return;
733-
}
722+
List<EntryHandle> snapshot = new ArrayList<>(cache.values());
723+
snapshot.sort((EntryHandle o1, EntryHandle o2) -> {
724+
long diff = o1.getLastGetTime() - o2.getLastGetTime();
725+
if (diff == 0) {
726+
return 0;
727+
}
728+
return diff > 0 ? 1 : -1;
729+
});
730+
snapshot.forEach(accumulator);
734731

735732
if (!evictable.isEmpty()) {
736733
LOGGER.log(Level.INFO, "found {0} evictable entries", evictable.size());

0 commit comments

Comments
 (0)