
线程传递增强之TransmittableThreadLocal
先来看TTL里面的几个重要属性及方法
TTL定义:
public class TransmittableThreadLocal extends InheritableThreadLocal 可以看到,TTL继承了ITL,意味着TTL首先具备ITL的功能。
再来看看一个重要属性holder:
/** * 这是一个ITL类型的对象,持有一个全局的WeakMap(weakMap的key是弱引用,同TL一样,也是为了解决内存泄漏的问题),里面存放了TTL对象 * 并且重写了initialValue和childValue方法,尤其是childValue,可以看到在即将异步时父线程的属性是直接作为初始化值赋值给子线程的本地变量对象(TTL)的 */ private static InheritableThreadLocal<Map<TransmittableThreadLocal<?
