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?
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:
private T setInitialValue() {
T value = initialValue();
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);
else
createMap(t, value);
return value;
}
and ThreadLocal.set():
public void set(T value) {
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);
else
createMap(t, value);
}