zzh

zzh

InheritableThreadLocal retrieves the threadLocal value of the parent thread.

1. get() and set() methods
  • get()
    image

  • set()

image

Here we can see that both methods use the getMap method to obtain the ThreadLocalMap object. Therefore, we can infer that this method is probably what allows InheritableThreadLocal to access values from the parent thread.

2. getMap() method

Next, let's compare the getMap() method in InheritableThreadLocal and ThreadLocal.

  • InheritableThreadLocal
    image

  • ThreadLocal

image

We can see that one obtains inheritableThreadLocals, while the other obtains threadLocals. The inheritableThreadLocals will be inherited by the child thread, allowing the child thread to access the threadLocal values of the parent thread (acting as a shared variable between threads).

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.