ThreadLocal<Long>
时间: 2023-08-25 22:18:22 浏览: 93
ThreadLocal<Long>是一个泛型类,用于在每个线程中创建一个独立的Long类型的变量副本。每个Thread线程内部都有一个ThreadLocalMap,ThreadLocal负责向map获取和设置线程的变量值。ThreadLocalMap是ThreadLocal的一个静态内部类,存储着ThreadLocal实例作为键值和对应线程的变量副本作为值。可以通过ThreadLocal的get()方法获取当前线程的变量副本,set()方法设置当前线程的变量副本,remove()方法移除当前线程的变量副本。在使用ThreadLocal时,每个线程都会有自己独立的变量副本,互相之间不会产生影响。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [ThreadLocal理解](https://blog.csdn.net/u010858605/article/details/113757955)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [多线程中的ThreadLocal 详解](https://blog.csdn.net/u014102727/article/details/80894342)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文