Consistent fine-tuning of synchronized and concurrent data structures
In particular, avoiding synchronized Sets and Maps wherever possible (preferring a ConcurrentHashMap even instead of a synchronized Set) and specifying appropriate ConcurrentHashMap initial capacities (even if we end up choosing 16).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,7 +54,7 @@ public class UrlFilenameViewController extends AbstractUrlViewController {
|
||||
private String suffix = "";
|
||||
|
||||
/** Request URL path String --> view name String */
|
||||
private final Map<String, String> viewNameCache = new ConcurrentHashMap<String, String>();
|
||||
private final Map<String, String> viewNameCache = new ConcurrentHashMap<String, String>(256);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
@@ -46,6 +45,7 @@ import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
@@ -56,7 +56,6 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
@@ -188,9 +187,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
private BeanExpressionContext expressionContext;
|
||||
|
||||
private final Map<Class<?>, ServletHandlerMethodResolver> methodResolverCache =
|
||||
new ConcurrentHashMap<Class<?>, ServletHandlerMethodResolver>();
|
||||
new ConcurrentHashMap<Class<?>, ServletHandlerMethodResolver>(64);
|
||||
|
||||
private final Map<Class<?>, Boolean> sessionAnnotatedClassesCache = new ConcurrentHashMap<Class<?>, Boolean>();
|
||||
private final Map<Class<?>, Boolean> sessionAnnotatedClassesCache = new ConcurrentHashMap<Class<?>, Boolean>(64);
|
||||
|
||||
|
||||
public AnnotationMethodHandlerAdapter() {
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
@@ -82,7 +81,7 @@ import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*
|
||||
* @deprecated in Spring 3.2 in favor of
|
||||
* @deprecated as of Spring 3.2, in favor of
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver ExceptionHandlerExceptionResolver}
|
||||
*/
|
||||
public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExceptionResolver {
|
||||
@@ -91,7 +90,7 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc
|
||||
private static final Method NO_METHOD_FOUND = ClassUtils.getMethodIfAvailable(System.class, "currentTimeMillis", (Class<?>[]) null);
|
||||
|
||||
private final Map<Class<?>, Map<Class<? extends Throwable>, Method>> exceptionHandlerCache =
|
||||
new ConcurrentHashMap<Class<?>, Map<Class<? extends Throwable>, Method>>();
|
||||
new ConcurrentHashMap<Class<?>, Map<Class<? extends Throwable>, Method>>(64);
|
||||
|
||||
private WebArgumentResolver[] customArgumentResolvers;
|
||||
|
||||
@@ -162,8 +161,7 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc
|
||||
final Class<? extends Throwable> thrownExceptionType = thrownException.getClass();
|
||||
Method handlerMethod = null;
|
||||
|
||||
Map<Class<? extends Throwable>, Method> handlers = exceptionHandlerCache.get(handlerType);
|
||||
|
||||
Map<Class<? extends Throwable>, Method> handlers = this.exceptionHandlerCache.get(handlerType);
|
||||
if (handlers != null) {
|
||||
handlerMethod = handlers.get(thrownExceptionType);
|
||||
if (handlerMethod != null) {
|
||||
@@ -171,8 +169,8 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc
|
||||
}
|
||||
}
|
||||
else {
|
||||
handlers = new ConcurrentHashMap<Class<? extends Throwable>, Method>();
|
||||
exceptionHandlerCache.put(handlerType, handlers);
|
||||
handlers = new ConcurrentHashMap<Class<? extends Throwable>, Method>(16);
|
||||
this.exceptionHandlerCache.put(handlerType, handlers);
|
||||
}
|
||||
|
||||
final Map<Class<? extends Throwable>, Method> matchedHandlers = new HashMap<Class<? extends Throwable>, Method>();
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.transform.Source;
|
||||
@@ -39,7 +38,6 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
@@ -82,7 +80,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
|
||||
private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
|
||||
|
||||
private final Map<Class<?>, ExceptionHandlerMethodResolver> exceptionHandlerCache =
|
||||
new ConcurrentHashMap<Class<?>, ExceptionHandlerMethodResolver>();
|
||||
new ConcurrentHashMap<Class<?>, ExceptionHandlerMethodResolver>(64);
|
||||
|
||||
private final Map<ControllerAdviceBean, ExceptionHandlerMethodResolver> exceptionHandlerAdviceCache =
|
||||
new LinkedHashMap<ControllerAdviceBean, ExceptionHandlerMethodResolver>();
|
||||
|
||||
@@ -157,14 +157,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
||||
|
||||
|
||||
private final Map<Class<?>, SessionAttributesHandler> sessionAttributesHandlerCache =
|
||||
new ConcurrentHashMap<Class<?>, SessionAttributesHandler>();
|
||||
new ConcurrentHashMap<Class<?>, SessionAttributesHandler>(64);
|
||||
|
||||
private final Map<Class<?>, Set<Method>> initBinderCache = new ConcurrentHashMap<Class<?>, Set<Method>>();
|
||||
private final Map<Class<?>, Set<Method>> initBinderCache = new ConcurrentHashMap<Class<?>, Set<Method>>(64);
|
||||
|
||||
private final Map<ControllerAdviceBean, Set<Method>> initBinderAdviceCache =
|
||||
new LinkedHashMap<ControllerAdviceBean, Set<Method>>();
|
||||
|
||||
private final Map<Class<?>, Set<Method>> modelAttributeCache = new ConcurrentHashMap<Class<?>, Set<Method>>();
|
||||
private final Map<Class<?>, Set<Method>> modelAttributeCache = new ConcurrentHashMap<Class<?>, Set<Method>>(64);
|
||||
|
||||
private final Map<ControllerAdviceBean, Set<Method>> modelAttributeAdviceCache =
|
||||
new LinkedHashMap<ControllerAdviceBean, Set<Method>>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ public class InternalPathMethodNameResolver extends AbstractUrlMethodNameResolve
|
||||
private String suffix = "";
|
||||
|
||||
/** Request URL path String --> method name String */
|
||||
private final Map<String, String> methodNameCache = new ConcurrentHashMap<String, String>();
|
||||
private final Map<String, String> methodNameCache = new ConcurrentHashMap<String, String>(16);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,8 +38,8 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
*/
|
||||
public class SimpleSpringPreparerFactory extends AbstractSpringPreparerFactory {
|
||||
|
||||
/** Cache of shared ViewPreparer instances: bean name --> bean instance */
|
||||
private final Map<String, ViewPreparer> sharedPreparers = new ConcurrentHashMap<String, ViewPreparer>();
|
||||
/** Cache of shared ViewPreparer instances: bean name -> bean instance */
|
||||
private final Map<String, ViewPreparer> sharedPreparers = new ConcurrentHashMap<String, ViewPreparer>(16);
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user