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

Discussion in 'Java' started by joes, Mar 14, 2007.

  1. joes

    joes Guest

    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
    joes, Mar 14, 2007
    #1
    1. Advertising

  2. joes

    Adam Maass Guest

    "joes" <> wrote:
    > 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
    Adam Maass, Mar 17, 2007
    #2
    1. Advertising

  3. joes

    Lew Guest

    Re: ServletFilters and Servlets: Is Running a "Request" in the sameThread?

    Adam Maass wrote:
    > 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
    Lew, Mar 17, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim
    Replies:
    4
    Views:
    6,989
  2. xarora
    Replies:
    1
    Views:
    480
    xarora
    Jul 26, 2005
  3. Berlin  Brown
    Replies:
    9
    Views:
    14,874
    Chris Smith
    Aug 31, 2006
  4. Miroslaw Makowiecki

    boost.thread library and the thread is running

    Miroslaw Makowiecki, Aug 9, 2007, in forum: C++
    Replies:
    1
    Views:
    463
    Victor Bazarov
    Aug 9, 2007
  5. QQ
    Replies:
    6
    Views:
    451
    Roedy Green
    Mar 28, 2008
Loading...

Share This Page