K
Ken Carroll
Can anyone tell me if the doFilter method is called on the same thread
as the servlet's service method ?
as the servlet's service method ?
Ken said:Can anyone tell me if the doFilter method is called on the same thread
as the servlet's service method ?
If I have something plugged in as a filter which sets some loggingSudsy said:I can't. But I have to ask a question in return: does it matter? I
would presume (but have no way of knowing without digging into the
source) that it wouldn't. A filter merely processes the request or
response. According to the javadocs it can choose to:
"4. a) Either invoke the next entity in the chain using the FilterChain
object (chain.doFilter()),
4. b) or not pass on the request/response pair to the next entity in the
filter chain to block the request processing"
There's no obligation on the part of the servlet container to run
filters in the same thread as the requested servlet. Obviously, if
a request filter opts to discontinue processing then the servlet
service method will never be invoked in the first place!
So why would you care?
If I have something plugged in as a filter which sets some logging
context for the thread servicing the request or does something with a
ThreadLocal on that thread. Currently this is done using a master
servlet which receives the request (service) and which then delegates
real request processing to a delegate (eg struts action servlet).
If I have something plugged in as a filter which sets some logging
context for the thread servicing the request or does something with a
ThreadLocal on that thread. Currently this is done using a master
servlet which receives the request (service) and which then delegates
real request processing to a delegate (eg struts action servlet).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.