commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <pj...@sfaf.org>
Subject RE: [lang] proposal: ThreadContext
Date Wed, 19 Jun 2002 19:19:28 GMT
I often use this in my code instead of ThreadLocals:

    public class StatefulThread extends Thread {
         // same constructors;

         private Object state;

         public Object getState() {
             return state;
         }

         public void setState(Object object) {
             this.state = object;
         }
    }

Then you can do ((StatefulThread)Thread.currentThread()).getState() to
get the variable.  It's much faster than ThreadLocal, which uses an
internal WeakHashMap.  Of course, the drawback is that it doesn't work
with something like Tomcat, where you can't control the creation of
threads.

-Paul


> -----Original Message-----
> From: Henri Yandell [mailto:bayard@generationjava.com]
> Sent: Wednesday, June 19, 2002 12:21 PM
> To: Jakarta Commons Developers List
> Subject: Re: [lang] proposal: ThreadContext
> 
> 
> As in java.lang.ThreadLocal? Or something different?
> 
> On Wed, 19 Jun 2002, Ola Berg wrote:
> 
> > OK, the script-kiddie with the bad ideas is back, this time 
> with a proposal for lang:
> >
> > When doing servlets you have the app-context, the 
> session-context and the request-context, where you can put 
> variables (or context attributes as they are called).
> >
> > What about a ThreadContext where you can put variables that 
> belongs to a certain thread? Wouldn\'t that make writing 
> thread safe things easier?
> >
> > Object o = ThreadContext.getAttribute( \"fooBar\"):
> >
> > /O
> >
> > --------------------
> > ola.berg@arkitema.se
> > 0733 - 99 99 17
> >
> > --
> > To unsubscribe, e-mail:   
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: 
<mailto:commons-dev-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message