tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <>
Subject Re: Question on Thread Local
Date Thu, 04 Sep 2014 05:35:29 GMT

On 2. September 2014 22:53:43 MESZ, Leon Rosenberg <> wrote:
>no :-)
>Allow me to provide an example.
>This class : (
>Is a ThreadLocal that is used to store some information, for example
>In the beginning of the processing I am calling
>MoSKitoWebUIContext.getCallContextAndReset(); //that initializes the
>context and than
>MoSKitoWebUIContext .getCallContext().setCurrentSession(HttpSession
>from this time on the link to current session is stored in the
>variable, and whereever in the call I need it, I can simply call
>MoSKitoWebUIContext .getCallContext().getCurrentSession() and obtain
>without explicitly passing it through call trees. This allows me to
>parameters from a very beginning of the processing to the very end of
>processing (or just everywhere) without passing them around and having
>in each and every method.

Does this method work with async servlets? I think that would loose the coupling between a
request and a thread. 


>Another popular example would be to store the Locale the user is in for
>P.S. of course you need to clean up the thread locals at the end of
>processing (at least in theory) and so on.
>On Tue, Sep 2, 2014 at 10:22 PM, Leo Donahue <>
>> On Tue, Sep 2, 2014 at 3:00 PM, Leon Rosenberg
>> wrote:
>> > From practical point of view ThreadLocal is a huge hashmap directly
>> the
>> > ThreadClass where you can store a map of variables.
>> > Something like Thread.Map<ThreadId, Map<String, Object>>, in which
>> can
>> > access variables that are 'attached' logically to the current
>> > In practice its a nice way to pass information through layers of
>> > without adding it explicitly as parameter to every function on the
>> > regards
>> > Leon
>> >
>> At some point in the web application, a ThreadLocal is instantiated
>and its
>> properties are set and then retrieved in a Filter.  Am I on track
>> How is that different or more helpful than instantiating any other
>> with property setters?
>> A POJO will be instantiated on every servlet request whereas the
>> ThreadLocal is only created once?

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message