mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge pull request #1118 from Alfresco/feature/ThreadSafeInstanceOfCache
Fix cache in NodeTypeUtility to be thread safe.
This commit is contained in:
@@ -26,8 +26,7 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -41,11 +40,12 @@ import org.alfresco.util.ParameterCheck;
|
||||
*/
|
||||
public class NodeTypeUtility
|
||||
{
|
||||
/** Static cache for results of types that are instances of other Alfresco types. */
|
||||
private static ConcurrentHashMap<String, Boolean> instanceOfCache = new ConcurrentHashMap<>();
|
||||
|
||||
/** Dictionary service */
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
|
||||
|
||||
/**
|
||||
* @param dictionaryService dictionary service
|
||||
*/
|
||||
@@ -66,24 +66,8 @@ public class NodeTypeUtility
|
||||
ParameterCheck.mandatory("className", className);
|
||||
ParameterCheck.mandatory("ofClassName", ofClassName);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
String key = className.toString() + "|" + ofClassName.toString();
|
||||
if (instanceOfCache.containsKey(key))
|
||||
{
|
||||
result = instanceOfCache.get(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ofClassName.equals(className) ||
|
||||
dictionaryService.isSubClass(className, ofClassName))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
instanceOfCache.put(key, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
return instanceOfCache.computeIfAbsent(key, k ->
|
||||
(ofClassName.equals(className) || dictionaryService.isSubClass(className, ofClassName)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user