当前位置:网站首页>Implement a ThreadLocal by yourself
Implement a ThreadLocal by yourself
2022-06-29 16:29:00 【hy;】
public class
> UserThreadLocal
<T> {
Map<Thread,T> thenCurrMap=new HashMap<>();
public void Set(T v){
thenCurrMap.put(Thread.currentThread(),v);
}
public T get(){
return thenCurrMap.getOrDefault(Thread.currentThread(),null);
}
static volatile int number=0;
public static void main(String[] args) {
UserThreadLocal<Integer> userThreadLocal=new UserThreadLocal<>();
for (int i=0;i<10;i++){
new Thread(new Runnable() {
@Override
public void run() {
userThreadLocal.Set(number++);
System.out.println(userThreadLocal.get());
}
}).start();
}
}
}
边栏推荐
- The rooster Electronic Society graphical programming real questions and answers analysis of the scratch grade test level 1 June 2022
- 教程|fNIRS数据处理工具包Homer2下载与安装
- Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
- 如何配置 logback?30分钟让你彻底学会代码熬夜敲
- 【Try to Hack】XML
- leetcode:232. Realize queue with stack [two stacks, one auxiliary and one simulated queue]
- locust性能压测工具
- How to embed iframes in WordPress
- MySQL cdc jobmanager 中存了哪些比较耗内存的数据呢?
- 毕业生迷茫,中年人焦虑,职场路怎么越走越宽?
猜你喜欢

Top the list for 10 consecutive years? What is the "most common" programming language for programmers?
![leetcode:535. Encryption and decryption of tinyurl [mapping of URL and ID, ID self increment]](/img/16/6684eaadc949e27c66a742100cb8f8.png)
leetcode:535. Encryption and decryption of tinyurl [mapping of URL and ID, ID self increment]

Cv5200 ad hoc network remote WiFi module, UAV wireless image transmission application, HD low delay scheme

Huaxia Fund: sharing of digital transformation practice achievements in the fund industry

把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...
![leetcode:139. Word splitting [DFS + memory]](/img/6f/8936ed3579c6a6dc3d8d312b413aff.png)
leetcode:139. Word splitting [DFS + memory]

星环科技数据安全管理平台 Defensor重磅发布

元数据管理Apache Atlas编译集成部署及测试

【OpenGL】杂谈一、通过鼠标拖拽实现相机绕空间中的某点进行球面旋转查看

To solve the stubborn problem of Lake + warehouse hybrid architecture, Star Ring Technology launched an independent controllable cloud native Lake warehouse integrated platform
随机推荐
STM32按键消抖——入门状态机思维
How to embed iframes in WordPress
UWB精准定位方案,厘米级高精度技术应用,智能配对感应技术
【Proteus仿真】数码管递加/递减带闪烁消隐显示
What are the financial products suitable for the poor in 2022?
自学编程能看得懂代码,但是自己写不出来怎么办
我,大厂测试员,降薪50%去国企,后悔了...
Stable currency risk profile: are usdt and usdc safe?
Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
Blue Bridge Cup 2015 CA provincial competition (filling the pit)
MySQL foundation - transaction
Flutter技术与实战(1)
美国芯片再遭重击,Intel或将被台积电击败而沦落至全球第三
The third sprint of Wei long La Tiao: the growth rate of performance declined, and Liu Weiping and Liu Fuping cashed out in advance
How to add a search box to your WordPress site
Sophon autocv: help AI industrial production and realize visual intelligent perception
Key sprite fighting monsters - multi window and multi thread background skills
Telnet+ftp to control and upgrade the equipment
SSL free certificate application, how about the actual effect of free SSL certificate?
实战 | 神奇的 conic-gradient 圆锥渐变