ThreadLocall
时间: 2023-10-17 20:31:05 浏览: 107
ThreadLocal是一个与线程绑定的变量。它与Synchronized一样,用于解决多线程并发访问的问题。 ThreadLocal可以在任何方法中轻松地获取到与当前线程绑定的对象。它的原理是通过ThreadLocal类的set()方法,可以将变量与当前线程关联起来,并存储在ThreadLocalMap中。如果当前线程已经有ThreadLocalMap,那么直接更新要保存的变量值;否则,创建ThreadLocalMap并存储变量值。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [ThreadLocal简介](https://blog.csdn.net/FourAu/article/details/125539139)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [浅谈ThreadLocal](https://blog.csdn.net/qq_36609994/article/details/121163994)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文