You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Harish Krishnaswamy <hk...@comcast.net> on 2004/02/29 05:49:13 UTC

[HiveMind] ThreadLocal snafu / karma please

I had an awful time with ThreadLocal today. Apparently the get() creates 
a new ThreadLocalMap for the thread (when one does not exist) after 
invoking the initialValue().

Current Implementation:


    *public* Object get() {
        Thread t = Thread.currentThread();
        ThreadLocalMap map = getMap(t);
        *if* (map != null) 
            *return* map.get(*this*);

        Object value = initialValue();
        createMap(t, value);
        *return* value;
    }

So if the initialValue() created another thread local variable, that 
variable is completely lost by the time get() is complete. It is not a 
very big deal had it been documented properly. I spent several hours 
trying to figure this out. Although a better implementation would be the 
following, I think.

Would be nice implementation:


    *public* Object get() {
        Thread t = Thread.currentThread();
        ThreadLocalMap map = getMap(t);
        *if* (map != null) 
            *return* map.get(*this*);

        Object value = initialValue();

        *if* (map != null) 
            map.set(*this*, value);
        *else*
            createMap(t, value);

        *return* value;
    }

So I finally fixed the ThreadLocalStorage problem, I guess! Howard, can 
I have karma to the sandbox cvs?

-Harish


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


Re: [HiveMind] ThreadLocal snafu / karma please

Posted by Harish Krishnaswamy <hk...@comcast.net>.
Thanks Craig!

Craig R. McClanahan wrote:

>Quoting Harish Krishnaswamy <hk...@comcast.net>:
>
>  
>
>>So I finally fixed the ThreadLocalStorage problem, I guess! Howard, can 
>>I have karma to the sandbox cvs?
>>
>>    
>>
>
>Karma granted on jakarta-commons-sandbox.
>
>  
>
>>-Harish
>>    
>>
>
>Craig
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>  
>

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


Re: [HiveMind] ThreadLocal snafu / karma please

Posted by Harish Krishnaswamy <hk...@comcast.net>.
Howard,

I am planning commit the ThreadLocalStorage and test changes tomorrow 
(its a small change). Let me know if I should put it to vote before 
commiting.

-Harish

Craig R. McClanahan wrote:

>Quoting Harish Krishnaswamy <hk...@comcast.net>:
>
>  
>
>>So I finally fixed the ThreadLocalStorage problem, I guess! Howard, can 
>>I have karma to the sandbox cvs?
>>
>>    
>>
>
>Karma granted on jakarta-commons-sandbox.
>
>  
>
>>-Harish
>>    
>>
>
>Craig
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>  
>

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


Re: [HiveMind] ThreadLocal snafu / karma please

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Quoting Harish Krishnaswamy <hk...@comcast.net>:

> 
> So I finally fixed the ThreadLocalStorage problem, I guess! Howard, can 
> I have karma to the sandbox cvs?
> 

Karma granted on jakarta-commons-sandbox.

> -Harish

Craig


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