ThreadLocal<T> 源码解析
在activeJDBC框架内部的实现中看到了 ThreadLocal 这个类,记录下了每个线程独有的连接 private static final ThreadLocal<HashMap<String, Connection>> connectionsTL = new ThreadLocal<>(); 感觉是个知识点,就打开源码看看了。先看一下源码里的解释 This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread (e.g., a user ID or Transaction ID). 这个鸟文,瞎翻译一下,就是: 这个类提供了供线程专享的变量。这些变量不同与其它普通的变量