I'm reading B. Goetz Java Concurrency in practice and now I'm at the section about how ThreadLocal
works. I used to thinking about it as a Map
-like structure, but he said that
Conceptually, you can think of a ThreadLocal as holding a Map that stores the thread-specific values, though this is not how it is actually implemented. The thread-specific values are stored in the Thread object itself; when the thread terminates, the thread-specific values can be garbage collected.
what does he mean? How can I store a thread-specific value in a thread?