Closed
Description
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>> {
@Override
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:
- ReflectionUtils slow down application startup on WebSphere [SPR-11882] #16501 ReflectionUtils slow down application startup on WebSphere