Possible Duplicate:
How is Java’s ThreadLocal implemented under the hood?
It’s been a while since I programmed in Java, and I want to freshen up on some theory.
How can I implement my own ThreadLocal from scratch?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. You can sub-class thread and copy the implementation in the source for Thread. Or you can just read the code but getting ThreadLocal right is tricky.
There are many tricky elements, the most obvious is preventing memory leaks from threads not being removed.
Even the existing implementation suffers from the issue that sub-classed ThreadLocal objects can prevent ClassLoaders from unloading.