当前位置:网站首页>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();
}
}
}
边栏推荐
- How can I repair a slow WordPress website?
- SAAS服务都有哪些优势
- 工具链赋能百家,地平线开启智能驾驶量产的“马太效应”
- What are the financial products suitable for the poor in 2022?
- UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
- Tutorial | fNIRS data processing toolkit homer2 download and installation
- 一个简单但是能上分的特征标准化方法
- 进阶 | webgl性能优化初尝
- Top the list for 10 consecutive years? What is the "most common" programming language for programmers?
- Technology sharing | broadcast function design in integrated dispatching
猜你喜欢

八年测开经验面试28K公司后,吐血整理出高频面试题和答案

DAP大屏主题开发说明

迪赛智慧数——其他图表(基本旭日图):毕业演讲高频词

水球图-利用动态波纹展示百分比

Science: the interrelated causes and consequences of sleep in the brain

数学知识复习:第一型曲线积分

CV5200自组网远程WiFi模组,无人机无线图传应用,高清低时延方案

BOE: with the arrival of the peak season in the second half of the year, the promotion and the release of new products, the demand is expected to improve

GNN笔记:消息传播模型

如何配置 logback?30分钟让你彻底学会代码熬夜敲
随机推荐
leetcode:232. Realize queue with stack [two stacks, one auxiliary and one simulated queue]
京东方:随着下半年旺季到来、促销拉动、新产品发布等影响,需求有望出现好转
按键精灵打怪学习-多窗口多线程后台判断人物、宠物血量和宠物快乐度
新股民如何网上开户?究竟网上开户是否安全么?
水球图-利用动态波纹展示百分比
Sophon autocv: help AI industrial production and realize visual intelligent perception
Which version of JVM is the fastest?
【Proteus仿真】8位数码管动态扫描显示变化数据
Accelerate the implementation of intelligent driving projects? You still lack a truth evaluation system
MySQL cdc jobmanager 中存了哪些比较耗内存的数据呢?
ssl免费证书申请,免费的ssl证书实际效果怎么样啊?
为防止被00后整顿,一公司招聘要求员工不能起诉公司
Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
星环科技数据安全管理平台 Defensor重磅发布
隐私计算助力数据的安全流通与共享
[proteus simulation] nixie tube +4x4 keyboard matrix key simple calculator
After 3 years of testing experience, do you know the state transition method for use case design?
apache atlas断点查看
Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
又拍云 Redis 的改进之路