CachedIntrospectionResults uses putIfAbsent where possible (for minimal write locking)

Issue: SPR-12102
master
Juergen Hoeller 10 years ago
parent 1ca0460534
commit 781a6d289e
  1. 8
      spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java

@ -188,13 +188,13 @@ public class CachedIntrospectionResults {
results = new CachedIntrospectionResults(beanClass); results = new CachedIntrospectionResults(beanClass);
if (ClassUtils.isCacheSafe(beanClass, CachedIntrospectionResults.class.getClassLoader()) || if (ClassUtils.isCacheSafe(beanClass, CachedIntrospectionResults.class.getClassLoader()) ||
isClassLoaderAccepted(beanClass.getClassLoader())) { isClassLoaderAccepted(beanClass.getClassLoader())) {
strongClassCache.put(beanClass, results); strongClassCache.putIfAbsent(beanClass, results);
} }
else { else {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Not strongly caching class [" + beanClass.getName() + "] because it is not cache-safe"); logger.debug("Not strongly caching class [" + beanClass.getName() + "] because it is not cache-safe");
} }
softClassCache.put(beanClass, results); softClassCache.putIfAbsent(beanClass, results);
} }
return results; return results;
} }
@ -295,7 +295,7 @@ public class CachedIntrospectionResults {
"; editor [" + pd.getPropertyEditorClass().getName() + "]" : "")); "; editor [" + pd.getPropertyEditorClass().getName() + "]" : ""));
} }
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd); pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
this.propertyDescriptorCache.put(pd.getName(), pd); this.propertyDescriptorCache.putIfAbsent(pd.getName(), pd);
} }
this.typeDescriptorCache = new ConcurrentHashMap<PropertyDescriptor, TypeDescriptor>(); this.typeDescriptorCache = new ConcurrentHashMap<PropertyDescriptor, TypeDescriptor>();
@ -348,7 +348,7 @@ public class CachedIntrospectionResults {
} }
void addTypeDescriptor(PropertyDescriptor pd, TypeDescriptor td) { void addTypeDescriptor(PropertyDescriptor pd, TypeDescriptor td) {
this.typeDescriptorCache.put(pd, td); this.typeDescriptorCache.putIfAbsent(pd, td);
} }
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) { TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {

Loading…
Cancel
Save