Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ public void invalidateQueryCache(Class classThatChanged) {
}
Set invalidations = this.queryResultsInvalidationsByClass.get(classThatChanged);
if (invalidations != null) {
for (Object queryKey : invalidations) {
this.queryResults.remove(queryKey);
synchronized (this.queryResults) {
for (Object queryKey : invalidations) {
this.queryResults.remove(queryKey);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queryResults is a ConcurrentHashMap. Could be rewritten to if (this.queryResults.keySet().removeAll(invalidations) invalidations.clear() so that locking is avoided?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is modification of invalidations while it's iterating.
The code can be rewritten according to your suggestion, but this will not eliminate the need of synchronization. Internally java.util.concurrent.ConcurrentHashMap.CollectionView#removeAll can iterate invalidations allso.

PS If invalidations.size() > queryResults.size() the CollectionView#removeAll will work faster then for (Object queryKey : invalidations) {}.

}
invalidations.clear();
}
}
Class superClass = classThatChanged.getSuperclass();
Expand Down