当前位置:网站首页>自己实现一个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();
}
}
}
边栏推荐
- CompletableFuture的入门
- Mysql database Basics: introduction to data types
- Is it safe to open a compass account and speculate in stocks? How individuals open accounts for stock trading
- SAAS服务都有哪些优势
- 面试官:说一下MySQL事务隔离级别?
- Key sprite fighting monsters - multi window and multi thread background skills
- How to create a login page in WordPress
- Time format GTM to Beijing time
- 元数据管理Apache Atlas编译集成部署及测试
- 哪个版本的JVM最快?
猜你喜欢
工具链赋能百家,地平线开启智能驾驶量产的“马太效应”
apache atlas断点查看
mysql数据库基础:数据类型介绍
论文笔记:E(n) Equivariant Graph Neural Networks
基于JSP实现毕业设计选题系统
After 3 years of testing experience, do you know the state transition method for use case design?
[everyone's project] launch the official website of rbatis ORM
Accelerate the implementation of intelligent driving projects? You still lack a truth evaluation system
A tour of gRPC:02 - 从proto生成代码
Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
随机推荐
把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...
ssl免费证书申请,免费的ssl证书实际效果怎么样啊?
如何在你的 wordpress 网站中添加搜索框
Interviewer: tell me about the MySQL transaction isolation level?
UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
C语言——printf打印进制前缀
自学编程能看得懂代码,但是自己写不出来怎么办
The latest agenda of dtcc2022 China database technology conference was released
Key wizard play monster learning - multi window and multi thread background judgment of character, pet blood volume and pet happiness
Science:大脑中睡眠的相互关联原因和结果
SSL free certificate application, how about the actual effect of free SSL certificate?
CompletableFuture的入门
实战 | Change Detection And Batch Update
Tianlong Babu TLBB series - how to make pets learn twelve full skills
关于开展2022年江苏省重点领域 首版次软件产品征集工作的通知
[proteus simulation] 8-bit nixie tube dynamic scanning display change data
Summary of common MySQL statements and commands
C language -- printf print base prefix
基础 | 在物理引擎中画圆弧
Cv5200 ad hoc network remote WiFi module, UAV wireless image transmission application, HD low delay scheme