You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Marco Mistroni <mm...@waersystems.com> on 2004/09/17 16:26:17 UTC
ThreadLocal bug
Hello,
I have seen in apache buglist a bug regarding ThreadLocal
I am using threadLocal in one of the classes used by my webservice...(I
am
Using Hibernate in my webservice)
Can anyone tell me what that bug was about?
As a matter of fact my code that uses ThreadLocal does not work.....
Thanx in advance and regards
Marco
Re: ThreadLocal bug
Posted by "matthew.hawthorne" <ma...@apache.org>.
Joseph Dane wrote:
> "matthew.hawthorne" <ma...@apache.org> writes:
>
>>I'm not sure if this is it -- but ThreadLocals don't work inside of
>>app servers that use thread pooling.
>
>
> that's news to me. care to clarify this?
>
> perhaps you mean that for a series of requests coming as part of a
> single session, the several requests aren't guaranteed to be serviced
> by the same thread. which is true, but a far cry from "ThreadLocals
> don't work inside app servers using thread pools".
Here's what I meant:
In servers that use thread pooling, ThreadLocal variables may not be
unique for each request.
I was using ThreadLocals to store invocation information, specific to
each request. But I noticed that, in some requests, instead of the
intialValue() method being called to initialize the ThreadLocal, it was
simply getting the already-initialized value. After doing some further
investigation and checking Thread.currentThread() and such, I realized
that the same Thread was being used for multiple requests, which
eliminated the uniqueness for each request that I needed to maintain.
Like I said in my earlier email, my technique was overly complicated. I
was able to solve the problem by using Axis'
MessageContext.getCurrentContext().
But you're right -- after re-reading what I wrote, I realized that I had
phrased it terribly. ThreadLocals were working exactly the way that
they're supposed to, I just didn't understand the way that the server
managed its threads.
Re: ThreadLocal bug
Posted by Joseph Dane <jd...@hawaii.edu>.
"matthew.hawthorne" <ma...@apache.org> writes:
> I'm not sure if this is it -- but ThreadLocals don't work inside of
> app servers that use thread pooling.
that's news to me. care to clarify this?
perhaps you mean that for a series of requests coming as part of a
single session, the several requests aren't guaranteed to be serviced
by the same thread. which is true, but a far cry from "ThreadLocals
don't work inside app servers using thread pools".
--
joe
Re: ThreadLocal bug
Posted by "matthew.hawthorne" <ma...@apache.org>.
Marco Mistroni wrote:
> Hello, I have seen in apache buglist a bug regarding ThreadLocal
> I am using threadLocal in one of the classes used by my webservice...(I
> am Using Hibernate in my webservice)
>
> Can anyone tell me what that bug was about?
> As a matter of fact my code that uses ThreadLocal does not work.....
I'm not sure if this is it -- but ThreadLocals don't work inside of
app servers that use thread pooling.
I ran into this problem with JBoss a while back, and had to use a
different technique to do what I wanted.
I was able to just use a basic HTTP session instead, which is probably
simpler anyway.