mirror of
https://github.com/spring-projects/spring-data-commons.git
synced 2026-05-02 11:18:18 +01:00
DATACMNS-1271 - Polishing.
Use ConcurrentHashMap in AnnotationBasedPersistentProperty for thread-safe annotation caching. Reintroduce eager cache check to prevent lambda instances on positive cache hits.
This commit is contained in:
committed by
Oliver Gierke
parent
78d21327bb
commit
7e7d4baa31
+8
-2
@@ -17,9 +17,9 @@ package org.springframework.data.mapping.model;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
private static final String SPRING_DATA_PACKAGE = "org.springframework.data";
|
||||
|
||||
private final @Nullable String value;
|
||||
private final Map<Class<? extends Annotation>, Optional<? extends Annotation>> annotationCache = new HashMap<>();
|
||||
private final Map<Class<? extends Annotation>, Optional<? extends Annotation>> annotationCache = new ConcurrentHashMap<>();
|
||||
|
||||
private final Lazy<Boolean> usePropertyAccess = Lazy.of(() -> {
|
||||
|
||||
@@ -230,6 +230,12 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
@SuppressWarnings("unchecked")
|
||||
private <A extends Annotation> Optional<A> doFindAnnotation(Class<A> annotationType) {
|
||||
|
||||
Optional<? extends Annotation> annotation = annotationCache.get(annotationType);
|
||||
|
||||
if (annotation != null) {
|
||||
return (Optional<A>) annotation;
|
||||
}
|
||||
|
||||
return (Optional<A>) annotationCache.computeIfAbsent(annotationType, type -> {
|
||||
|
||||
return getAccessors() //
|
||||
|
||||
Reference in New Issue
Block a user