Skip to content

Commit 902b877

Browse files
mp911deodrotbohm
authored andcommitted
DATACMNS-1364 - Polishing.
Use weak references in annotation and property annotation cache to retain references until the last GC root is cleared. Remove trailing whitespaces. Reformat. Original pull request: #304.
1 parent e163a69 commit 902b877

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.Serializable;
2222
import java.lang.annotation.Annotation;
2323
import java.util.*;
24+
import java.util.concurrent.ConcurrentHashMap;
2425
import java.util.stream.Collectors;
2526

2627
import org.springframework.core.annotation.AnnotatedElementUtils;
@@ -31,7 +32,9 @@
3132
import org.springframework.data.util.TypeInformation;
3233
import org.springframework.lang.Nullable;
3334
import org.springframework.util.Assert;
34-
import org.springframework.util.LinkedMultiValueMap;
35+
import org.springframework.util.CollectionUtils;
36+
import org.springframework.util.ConcurrentReferenceHashMap;
37+
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
3538
import org.springframework.util.MultiValueMap;
3639
import org.springframework.util.StringUtils;
3740

@@ -95,8 +98,9 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
9598
this.associations = comparator == null ? new HashSet<>() : new TreeSet<>(new AssociationComparator<>(comparator));
9699

97100
this.propertyCache = new ConcurrentHashMap<>();
98-
this.annotationCache = new ConcurrentReferenceHashMap<>();
99-
this.propertyAnnotationCache = CollectionUtils.toMultiValueMap(new ConcurrentReferenceHashMap<>());
101+
this.annotationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
102+
this.propertyAnnotationCache = CollectionUtils
103+
.toMultiValueMap(new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK));
100104
this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE;
101105
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
102106
}

0 commit comments

Comments
 (0)