private ThreadLocal<Map<String,Object>> THREAD_LOCAL=new ThreadLocal()<>
1.To explian the difference encapsulate ThreadLocal by myself and use it's ThreadLocalMap. 2.How to select suitable Data Structures to encapsulate in coding?
private ThreadLocal<Map<String,Object>> THREAD_LOCAL=new ThreadLocal()<>
1.To explian the difference encapsulate ThreadLocal by myself and use it's ThreadLocalMap. 2.How to select suitable Data Structures to encapsulate in coding?
Copyright © 2021 Jogjafile Inc.
The
ThreadLocal.ThreadLocalMapclass is an internal class used by theThreadLocalAPI to represent the thread locals. It has special properties that make it suitable for that use-case ... and not others.By contrast
is declaring a thread local that will contain a
Mapvalue.THREAD_LOCALis not the map itself. Rather, it says that any thread have one of those values ... and you access it using the (unhelpfully named)THREAD_LOCALinstance.In the fullness of time, your thread local's (
Map) values will be held in an instance ofThreadLocalMapthat is associated with a givenThread. But that is an implementation detail.Basically, these are two different things. The
ThreadLocalMapholds all of the thread-local values for a thread. YourMapwill be just one of those values.But you don't need to understand
ThreadLocalMap. It is internal. And implementation detail. Not visible to your code. Code to theThreadLocalAPI and ignore what happens under the hood. (Or if you are pathologically curious ... download and read the source code for yourself.)Not sure what you are asking here. But you shouldn't be directly using or depending on
ThreadLocalMapin your code.