Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can someone share his experience with where to use ThreadLocal variable in Java, what caution has to be taken while using it and what are the pros and cons of ThreadLocal variable.

Thanks
Posted

Google can!

A quick google using your subject copy and pasted as the search term gave over 200,000 hits: http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=ThreadLocal+variable+in+Java[^]

The top hit explains it pretty nicely: Class ThreadLocal[^]

Learn to use Google: it is a lot faster and less effort than asking a question like this!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Apr-11 22:21pm    
OP Commented:

Thanks for you suggestion OriginalGriff but I am not impressed with your answer. I am looking for some practical experience guys who has actually used such code in live environment and aware of any potential mistake e.g. memory leaks etc. anyway thanks.
Thanks, I have found answer and learned myself and documented here on my post :
How to use ThreadLocal variable in Java[^], in which I have document approach I used to make SimpleDateFormat thread-safe and other is How ThreadLocal creates memory leak in Java[^]which is about potential risk of using it in manged environment.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900