Assuming a system contains 2 threads. One of them interacts with a ThreadLocal while the other does not.
What happens to ThreadLocal in the class that does not interact with the ThreadLocal?
- Is it ever initialized?
- Does it take up any memory?
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.
There will be only one ThreadLocal object. Each Thread has a lazily initialised map of values of all initialised ThreadLocal objects. It means only the first Thread will have an extra Map object with one value, and nothing will change for the second thread.
See ThreadLocal.setInitialValue() for details:
and ThreadLocal.set():