The only difference between InheritableThreadLocal and ThreadLocal occurs
when the thread local variable is initialized. Accessing/setting the value is
the same in both cases. Here is a simple example:

public final class SecurityAssociation
{
    private static ThreadLocal thread_principal = new InheritableThreadLocal();

    public static Principal getPrincipal()
    {
        return (Principal) thread_principal.get();
    }

    public static void setPrincipal( Principal principal )
    {
        thread_principal.set( principal );
    }

}

Now any thread can set the current principal via SecurityAssociation.setPrincipal()
and get the current principal via SecurityAssociation.getPrincipal(). If a thread
sets the principal and then creates a child thread, the child thread sees the parent's
value. This can be overriden by creating a subclass of InheritableThreadLocal.

----- Original Message ----- 
From: "Seemantini Godbole" <[EMAIL PROTECTED]>
To: "'LOG4J Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Tuesday, June 12, 2001 2:38 PM
Subject: RE: while we are talking about NDC


> Anders,
> 
> Thanks for pointing out. Yes, that is basically the same idea. I like Ceki's
> idea of using InheritableThreadLocal better. However, does anybody have any
> example code showing some usage. I tried to read ThreadLocal as well, and
> have not completely grasped the concept.
> 
> I also like Ceki's idea about using '%x{server}' instead of inventing new
> characters for Pattern* classes.
> 
> Thanks again.
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to