Same thread for ServletRequestListener and Servlet request?
DoesServletRequestListenermethods execute in the same thread that the Servlet.servicemethod?
I wonder if the answer is always 'yes'. And I hope it will. I've been reading the specs but found nothing related.
I think it's an important issue because this way you can take advantage and share data between listener and request in a ThreadLocal object for a request.
Can anyone help me?
Thanks in advance.
Message was edited by:
pucherico
[499 byte] By [
puchericoa] at [2007-11-27 10:48:26]

# 2
I've checked it up for Tomcat (version 5). I can say it is true for Tomcat: For a given request, the service method and request listeners are executed in the same thread. But who can say this is true for all Application Servers....! and who can say it will be true for future version of Tomcat!
Because of the lack in the spec (I haven't found any comment on this subject) I am still not sure if I can rely on this property!
# 4
You would be quite right (thanks for your answser). However using request attributes is not an option when I must gain access to some thread local resource from my model (service layer). In a MVC design, the model has no access to the view. My model shouldn't be request-dependent (it can be use in a swing app for instance).
ThreadLocal is the clean independent alternative to gain access from the model.