Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnnotationUtils should use threadsafe ConcurrentMap (contention) [SPR-12878] #17476

spring-projects-issues opened this issue Apr 1, 2015 · 2 comments
in: core type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Apr 1, 2015

Johann Burkard opened SPR-12878 and commented

	private static final Map<Class<?>, Boolean> annotatedInterfaceCache = new WeakHashMap<Class<?>, Boolean>();
	private static boolean isInterfaceWithAnnotatedMethods(Class<?> iface) {
		synchronized (annotatedInterfaceCache) {
			Boolean flag = annotatedInterfaceCache.get(iface);

is a point of contention in my app and should be replaced by something like ConcurrentSkipListMap (but not ConcurrentHashMap because ConcurrentSkipListMap uses 1/10th the memory initially). Here's a Comparator for WeakReference:

import java.lang.ref.WeakReference;
import java.util.Comparator;

import org.springframework.util.ObjectUtils;

public class WeakReferenceClassComparator implements Comparator<WeakReference<Class>> {

    public int compare(WeakReference<Class> o1, WeakReference<Class> o2) {
        if (o1.get() == null && o2.get() == null) {
            return 0;
        return new Integer(ObjectUtils.nullSafeHashCode(o1.get())).compareTo(ObjectUtils.nullSafeHashCode(o2.get()));


Affects: 4.0.5, 4.0.8

Issue Links:

  • #16501 ReflectionUtils slow down application startup on WebSphere
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 1, 2015

Juergen Hoeller commented

This has been addressed in the 4.1 line already, as part of #16501, using our own ConcurrentReferenceHashMap there now.

Note that the 4.0.x line has ended in the meantime, with no further releases planned. Please upgrade to 4.1.6 right away!


Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 1, 2015

Johann Burkard commented

Thanks for the update, Jürgen. I'll tro to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: enhancement
None yet

No branches or pull requests

2 participants