当前位置:网站首页>自己实现一个ThreadLocal
自己实现一个ThreadLocal
2022-06-29 16:08: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();
}
}
}
边栏推荐
- Summary of common MySQL statements and commands
- 一个简单但是能上分的特征标准化方法
- 稳定币风险状况:USDT 和 USDC 安全吗?
- 实践 | 脚本错误量极致优化-让脚本错误一目了然
- 小程序在产业互联网有「大」作为
- Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
- mysql数据库基础:数据类型介绍
- [proteus simulation] 8-bit nixie tube dynamic scanning display change data
- How do I create a contact form in WordPress?
- Differences between virtual hosts, WordPress hosts and virtual hosts
猜你喜欢

穩定幣風險狀况:USDT 和 USDC 安全嗎?

连续10年霸榜第一?程序员「最常用」的编程语言是它?

The latest agenda of dtcc2022 China database technology conference was released

工具链赋能百家,地平线开启智能驾驶量产的“马太效应”

真正的测试 =“半个产品+半个开发”?

基于JSP实现毕业设计选题系统

The rooster Electronic Society graphical programming real questions and answers analysis of the scratch grade test level 1 June 2022

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

元数据管理Apache Atlas编译集成部署及测试
![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]
随机推荐
mysql数据库基础:数据类型介绍
C11新特性——auto、decltype类型指示符
水球图-利用动态波纹展示百分比
locust性能压测工具
如何在你的 wordpress 网站中添加搜索框
DAP large screen theme development description
UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
[everyone's project] launch the official website of rbatis ORM
指南针开户炒股是否安全?个人怎样开户炒股
How to create a login page in WordPress
关于组织开展2022年南京市创新产品(第一批)申报工作的通知
暑期数据可视化分析展示效果
Nanjing University: Discussion on the training scheme of digital talents in the new era
Which version of JVM is the fastest?
leetcode:535. Encryption and decryption of tinyurl [mapping of URL and ID, ID self increment]
[proteus simulation] nixie tube +4x4 keyboard matrix key simple calculator
高级性能测试工程师面试必问十大问题
Magento 和 WordPress 的区别
Time format GTM to Beijing time
STM32按键消抖——入门状态机思维