当前位置:网站首页>Collection and map thread safety problem solving
Collection and map thread safety problem solving
2022-04-23 06:09:00 【linsa_ pursuer】
1.ArrayList Thread unsafe ( There is no reentrant lock ) resolvent Vector(synchronized) Collections(synchronized) CopyOnWriteArrayList(ReentrantLock)
2.HashSet——》CopyOnWriteArraySet
3.HashMapt——》ConcurrentHashMap
package juc.two;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* ArrayList Thread unsafe ( There is no reentrant lock )
* resolvent Vector(synchronized) Collections(synchronized) CopyOnWriteArrayList(ReentrantLock)
*/
public class ThreadDemo4 {
public static void main(String[] args) {
// establish ArrayList aggregate
//List<String> list = new ArrayList<>();
//Vector solve
//List<String> list = new Vector<>();
//Collections solve
//List<String> list = Collections.synchronizedList(new ArrayList<>());
//CopyOnWriteArrayList solve
//List<String> list = new CopyOnWriteArrayList<>();
/*for(int i = 0; i<30; i++){
new Thread(()->{
// Add content to collection
list.add(UUID.randomUUID().toString().substring(0,8));
// Get content from collection
System.out.println(list);
},String.valueOf(i)).start();
}*/
// demonstration HashSet
//Set<String> set = new HashSet<>();
//Set<String> set = new CopyOnWriteArraySet<>();
/*for(int i = 0; i<30; i++){
new Thread(()->{
// Add content to collection
set.add(UUID.randomUUID().toString().substring(0,8));
// Get content from collection
System.out.println(set);
},String.valueOf(i)).start();
}*/
// demonstration HashMap
//Map<String,String> map = new HashMap<>();
Map<String,String> map = new ConcurrentHashMap<>();
for(int i = 0; i<30; i++){
String key = String.valueOf(i);
new Thread(()->{
// Add content to collection
map.put(key,UUID.randomUUID().toString().substring(0,8));
// Get content from collection
System.out.println(map);
},String.valueOf(i)).start();
}
}
}
版权声明
本文为[linsa_ pursuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533259314.html
边栏推荐
- 去噪论文——[Noise2Void,CVPR19]Noise2Void-Learning Denoising from Single Noisy Images
- 数字图像处理基础(冈萨雷斯)二:灰度变换与空间滤波
- Common programming records - parser = argparse ArgumentParser()
- 无监督去噪——[TMI2022]ISCL: Interdependent Self-Cooperative Learning for Unpaired Image Denoising
- Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
- Optional best practices
- 编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
- 图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
- 自動控制(韓敏版)
- Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
猜你喜欢

LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising

Pytoch -- data loading and processing

Pytorch——数据加载和处理

Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code

Opensips (1) -- detailed process of installing opensips

Configure domestic image accelerator for yarn

Pytorch学习记录(十二):学习率衰减+正则化

Pyemd installation and simple use

List segmentation best practices

Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
随机推荐
自动控制(韩敏版)
線性代數第一章-行列式
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
A general U-shaped transformer for image restoration
JSP syntax and JSTL tag
How does MySQL convert stored seconds into dates
JDBC operation transaction
Opensips (1) -- detailed process of installing opensips
Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
Rsync for file server backup
8. Integer Decomposition
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
Supply chain service terms
Remedy after postfix becomes a spam transit station
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package
Fundamentals of digital image processing (Gonzalez) I
CONDA virtual environment management (create, delete, clone, rename, export and import)
深度学习基础——简单了解meta learning(来自李宏毅课程笔记)