tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leon Rosenberg <rosenberg.l...@gmail.com>
Subject Re: Question on Thread Local
Date Tue, 02 Sep 2014 20:00:53 GMT
>From practical point of view ThreadLocal is a huge hashmap directly in the
ThreadClass where you can store a map of variables.
Something like Thread.Map<ThreadId, Map<String, Object>>, in which you can
access variables that are 'attached' logically to the current Thread.
In practice its a nice way to pass information through layers of code
without adding it explicitly as parameter to every function on the way.
regards
Leon

P.S. of course there are some technical aspects like ability to be passed
to the spawned threads etc, which I didn't mention :-)


On Tue, Sep 2, 2014 at 9:47 PM, Leo Donahue <donahulf2@gmail.com> wrote:

> I've been reading about using Thread Local in web applications and the
> general use case is to generate a transaction id in a filter so that the
> rest of the web application running in the thread local will have access to
> that transaction id.
>
> Thread Local is essentially a way to create a global variable so that you
> don't have to create a bean that generates said global data and pass that
> bean around to other classes, or inject it into the other classes?
>
> I am not sure I understand the difference between per-thread requests and
> servlet requests that already run in their own thread.
>
> In other words, what is the difference between using a Thread Local
> variable vs any other variable that is created inside a filter, or during a
> normal servlet request?
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message