JAVA foundation Series: ThreadLocal ThreadLocal Source interpret 2019/03 interview questions - based concurrency

1. Ideas

    1. What is ThreadLocal?
      ThreadLocal class can be understood as the name suggests thread-local variables. This means that if the definition of a ThreadLocal, ThreadLocal each thread to read and write in this thread is isolated from each other does not affect. It provides a variable data each thread has its own independent copy of the threads in order to achieve a closed system.

    2. It is a general idea of how to achieve?
      Thread class has an instance variable of type ThreadLocal.ThreadLocalMap threadLocals, which means that each thread has its own ThreadLocalMap. ThreadLocalMap has its own independent implementation of its key can simply be treated as ThreadLocal, value is placed in the code values (in fact key is not ThreadLocal itself, but its a weak reference). Each thread when stuffed into a ThreadLocal value, will go to their ThreadLocalMap in existence, but also to a ThreadLocal read as a reference to find the corresponding map in their key, in order to achieve a thread isolation.

2. graphic

2.1 Location

2.2 Structure FIG.

  

2.3 Source diagram

Diagram 2.4 Memory

 

  

 

 

 

Reference Site

  1. ThreadLocal- depth interview will be asked to resolve
  2. Java source code to resolve real - ThreadLocal principle
  3. [Java] illustrates concurrent study five ThreadLocal
  4. A thorough understanding of ThreadLocal
  5. ThreadLocal source Interpretation
  6. Sike talk of Java ThreadLocal source (based on JDK1.8)
  7. Java interview will ask, ThreadLocal final chapter
  8. 2019/03 interview questions - based concurrency
  9. In-depth understanding of ThreadLocal (these should not be ignored)
  10. https://www.iteye.com/topic/1123824

Guess you like

Origin www.cnblogs.com/haimishasha/p/11008683.html