According to
http://forum.springsource.org/showth...-thread-safety
DispatcherServlet is threadsafe.
So, I will assume
public void setDetectAllHandlerMappings(boolean detectAllHandlerMappings) {
this.detectAllHandlerMappings = detectAllHandlerMappings;
}
is also thread safe and there is no race condition in setting the detectAllHandlerMappings instance field.
Apart from my why the documentation for DispatcherServlet does not mention that it is thread safe, I have a few more questions.
a) Are the methods mentioned below threadsafe?
b) Is it because the methods are thread safe or the entire Servlet is thread safe?
c) If it is just the method that is thread safe, is it because this happens only during initialization where only one thread is active?
1) org.springframework.web.servlet.FrameworkServlet.s etContextConfigLocation(java.lang.String)
2) org.springframework.web.servlet.ResourceServlet.se tAllowedResources(java.lang.String)
3) org.springframework.web.servlet.mvc.AbstractFormCo ntroller.setBindOnNewForm(boolean)
4) org.springframework.web.servlet.mvc.AbstractUrlVie wController.setUrlPathHelper(org.springframework.w eb.util.UrlPathHelper)
5) org.springframework.web.servlet.mvc.AbstractWizard FormController.setPageAttribute(java.lang.String)
6) org.springframework.web.servlet.mvc.BaseCommandCon troller.setCommandClass(java.lang.Class)
7) org.springframework.web.servlet.mvc.CancellableFor mController.setCancelParamKey(java.lang.String)
8) org.springframework.web.servlet.mvc.Parameterizabl eViewController.setViewName(java.lang.String)
9) org.springframework.web.servlet.mvc.ServletForward ingController.setServletName(java.lang.String)
10) org.springframework.web.servlet.mvc.ServletWrappin gController.setServletClass(java.lang.Class)
11) org.springframework.web.servlet.mvc.SimpleFormCont roller.setSuccessView(java.lang.String)
12) org.springframework.web.servlet.mvc.UrlFilenameVie wController.setPrefix(java.lang.String)
13) org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.registerHandlerMethods(java.la ng.Object)
14) org.springframework.web.servlet.mvc.AbstractUrlVie wController.setUrlDecode(boolean)
15) org.springframework.web.servlet.mvc.BaseCommandCon troller.createCommand()
As the link above points out,
"So, generally speaking, in a Spring application, all your major components are singletons. This means there is only one of each. It does not mean, however, that multiple threads can't use those components concurrently. They certainly can. This is precisely why code should be made threadsafe. So, getting back to my previous note, the best way to promote thread-safety is to code your components so that they are stateless."
Now, all these servlets/controllers seem to maintain state and I want to be certain that they are thread safe before I can start using spring.


Reply With Quote
