ServletFilters and Servlets: Is Running a "Request" in the same Thread?

J

joes

Hello

I have a basic question regarding Servlet and ServletFilters. If I do
have a filter, can I assume that the request is running in the same
thread? Or could it be that the filter is running in another context
as the servlet?
Background: we have an existing framework which is using ThreadLocal
variables and therefore it is essential to know how the specification
of a servletciontainer does look like and if someone has experiences
on that?

Many thanks

regards
Mark
 
A

Adam Maass

joes said:
Hello

I have a basic question regarding Servlet and ServletFilters. If I do
have a filter, can I assume that the request is running in the same
thread? Or could it be that the filter is running in another context
as the servlet?
Background: we have an existing framework which is using ThreadLocal
variables and therefore it is essential to know how the specification
of a servletciontainer does look like and if someone has experiences
on that?

Many thanks

I'm not exactly sure what the specification says, but the reference
implementation (IE, Tomcat) runs the ServletFilter and the chained target
Servlet in the same thread for the same request.

It's a pretty safe bet that other implementations of the Servlet
specification do the same thing. Even if the spec itself leaves this detail
underspecified.

-- Adam Maass
 
L

Lew

Adam said:
I'm not exactly sure what the specification says, but the reference
implementation (IE, Tomcat) runs the ServletFilter and the chained
target Servlet in the same thread for the same request.

It's a pretty safe bet that other implementations of the Servlet
specification do the same thing. Even if the spec itself leaves this
detail underspecified.

Don't you mean "unspecified"? Meaning you can't count on the behavior?

-- Lew
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top