当前位置:网站首页>异步时父子线程间的ThreadLocal传递问题
异步时父子线程间的ThreadLocal传递问题
2022-07-26 04:57:00 【知识浅谈】
异步时父子线程间的ThreadLocal传递问题
ThreadLocal的子类InheritableThreadLocal其实已经帮我们处理好了,通过这个组件可以实现父子线程之间的数据传递,在子线程中能够父线程中的ThreadLocal本地变量。
我们发现InheritableThreadLocal中createMap,以及getMap方法处理的对象不一样了,其中在ThreadLocal中处理的是threadLocals,而InheritableThreadLocal中的是inheritableThreadLocals。
createMap代码如下:
void createMap(Thread t, T firstValue) {
t.inheritableThreadLocals = new ThreadLocalMap(this, firstValue);
}
代码的意思是在Thread先获取父亲线程parent(即要创建子线程的当前这个线程)。当父亲线程中对inherThreadLocals进行了赋值,就会把当前线程的本地变量(也就是父线程的inherThreadLocals)进行createInheritedMap方法操作。查看源码createInheritedMap方法,源码可知此操作就是将赋线程的threadLocalMap传递给子线程。
边栏推荐
- UE4 two ways to obtain player control
- Ggjj, do you have a look at this problem? Does caching cause cross domain problems?
- Redis解决库存超卖问题
- 2022 Hangdian multi school DOS card (line segment tree)
- [learning notes] agc041
- 2022杭电多校第二场 A.Static Query on Tree(树剖)
- Database startup message: ora-29702: error occurred in cluster group service
- Principle of image nonlocal mean filtering
- vector详解和迭代器失效问题
- There was an unexpected error (type=method not allowed, status=405)
猜你喜欢

columns in GROUP BY clause; this is incompatible with sql_ mode=only_ full_ group_ By mysql8.0 solution

Recursive implementation of exponential enumeration

columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by mysql8.0解决办法

Calculate the curvature of discrete points (matlab)

数组排序1

Bsdiff and bspatch incremental updates

擅长C(暑假每日一题 6)

这种是我的vs没连上数据库吗

汉字风格迁移篇---通过生成对抗网络学习一对多程式化汉字的转换和生成

「游戏引擎 浅入浅出」4. 着色器
随机推荐
C语言——指针一点通※
New knowledge in big homework
2022杭电多校 DOS Card(线段树)
擅长C(暑假每日一题 6)
What are the restrictions on opening futures accounts? Where is the safest place to open an account?
The importance of supporting horizontal expansion of time series database
Array sort 1
MySQL 执行失败的sql是否会计入慢查询?
NFT的几种发行方式你都了解过吗?不同的发行方式有什么优缺点?
解决 Incorrect string value: ‘\xF0\x9F\x98\xAD“,...‘ for column ‘commentContent‘ at row 1 报错
User defined type details
Sliding window -- leetcode solution
Switch to router technology: OSPF single zone configuration, OSPF multi zone and end zone
科技论文翻译,俄语文档的语法有何特点
vector详解和迭代器失效问题
Stm32fsmc extended SRAM
Good at C (summer vacation daily question 6)
9、 File upload and download
Js手写函数之节流防抖函数
Niuke-top101-bm32