Skip to content

Commit 781a6d2

Browse files
committed
CachedIntrospectionResults uses putIfAbsent where possible (for minimal write locking)
Issue: SPR-12102
1 parent 1ca0460 commit 781a6d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ static CachedIntrospectionResults forClass(Class<?> beanClass) throws BeansExcep
188188
results = new CachedIntrospectionResults(beanClass);
189189
if (ClassUtils.isCacheSafe(beanClass, CachedIntrospectionResults.class.getClassLoader()) ||
190190
isClassLoaderAccepted(beanClass.getClassLoader())) {
191-
strongClassCache.put(beanClass, results);
191+
strongClassCache.putIfAbsent(beanClass, results);
192192
}
193193
else {
194194
if (logger.isDebugEnabled()) {
195195
logger.debug("Not strongly caching class [" + beanClass.getName() + "] because it is not cache-safe");
196196
}
197-
softClassCache.put(beanClass, results);
197+
softClassCache.putIfAbsent(beanClass, results);
198198
}
199199
return results;
200200
}
@@ -295,7 +295,7 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
295295
"; editor [" + pd.getPropertyEditorClass().getName() + "]" : ""));
296296
}
297297
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
298-
this.propertyDescriptorCache.put(pd.getName(), pd);
298+
this.propertyDescriptorCache.putIfAbsent(pd.getName(), pd);
299299
}
300300

301301
this.typeDescriptorCache = new ConcurrentHashMap<PropertyDescriptor, TypeDescriptor>();
@@ -348,7 +348,7 @@ private PropertyDescriptor buildGenericTypeAwarePropertyDescriptor(Class<?> bean
348348
}
349349

350350
void addTypeDescriptor(PropertyDescriptor pd, TypeDescriptor td) {
351-
this.typeDescriptorCache.put(pd, td);
351+
this.typeDescriptorCache.putIfAbsent(pd, td);
352352
}
353353

354354
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {

0 commit comments

Comments
 (0)