tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Filters and ServletContext
Date Fri, 09 Nov 2001 02:43:44 GMT

On 9 Nov 2001, Dr. Evil wrote:

> Date: 9 Nov 2001 02:18:46 -0000
> From: Dr. Evil <>
> Reply-To: Tomcat Users List <>
> To:
> Subject: Re: Filters and ServletContext
> Thanks Craig.  That's just what I needed to know.  Filters are an
> awesome way of doing a lot of things.

I agree -- when we were first designing the Filter API for servlet 2.3 (in
the JSR-053 expert group), I predicted that this would be the best of the
new features.  It's incredibly powerful, but still conceptually simple
enough to understand.

>  Basically, what I will do is
> have a big store of objects in a hashmap in the ServletContext.  When
> a request comes in, a filter will pull the appropriate object from the
> hashmap and puts it in the HttpServletRequest object before passing it
> on.  This is excellent.  Now I have to make sure that I fully
> understand all the thread issues associated with using a HashMap for
> this so that I don't get a corrupted HashMap.

Filters have the same threading characterstics as servlets -- there is a
single instance per filter definition.

For your HashMap stored as a servlet context attribute, there are two

* If the HashMap can be modified on the fly while the
  application runs, you should synchronize all gets
  and sets.

* If the HashMap is created at startup time (perhaps
  in a ServletContextListener.contextStarted() method),
  and *never* modified, then you don't have to synchronize
  the gets.

> Thanks!


To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message