当前位置:网站首页>[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
2022-07-03 08:32:00 【keeper42】
1、 Synchronization container
The main representatives are Vector and Hashtable, as well as Collections.synchronizedXxx etc. .
The granularity of the lock is the current object as a whole .
Iterators fail in time , That is to say, it is found to be modified in the process of iteration , Will throw ConcurrentModificationException.
2、 Concurrent container
The main representatives are ConcurrentHashMap、CopyOnWriteArrayList、ConcurrentSkipListMap、ConcurrentSkipListSet
The granularity of locks is decentralized 、 Fine grained , That is, reading and writing use different locks .
Iterators have weak consistency , That is, it can tolerate concurrent modification , Don't throw ConcurrentModificationException.
3、 Blocking queues
The main representatives are LinkedBlockingQueue、ArrayBlockingQueue、PriorityBlockingQueue(Comparable,Comparator)、SynchronousQueue.
Provides blocking put and take Method , And support timed offer and poll Method .
Applicable to producers 、 Consumer model ( Thread pools and work queues -Executor)
It is also a synchronization container
4、 Double ended queue and work secret
The main representatives are ArrayDeque and LinkedBlockingDeque.
significance : Just as blocking queues apply to producer consumer patterns , Double ended queue is also applicable to another mode , That is, work secret . In the producer - In consumer design , All consumers share a work queue , And in working secret , Each consumer has its own double ended queue .
If a consumer has completed all the work in their double ended queue , Then it can secretly get work from the end of the double ended queue of other consumers . Better scalability , This is because worker threads do not compete on a single shared task queue .
Most of the time , They all just access their own double ended queues , Thus greatly reducing the competition . When a worker thread needs to access another queue , It gets work from the end of the queue instead of the head , Therefore, the competition on the queue is further reduced .
边栏推荐
- go 解析身份证
- Delete the last character of the string in golang
- Clion toolchains are not configured configure disable profile problem solving
- Simple demo of solving BP neural network by gradient descent method
- Osgconv tool usage
- 【Rust 笔记】13-迭代器(上)
- Downward compatibility and upward compatibility
- P1596 [USACO10OCT]Lake Counting S
- Three characteristics
- [linear table] basic operation of bidirectional linked list specify node exchange
猜你喜欢
Data analysis exercises
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)
Graphics_ Games101/202 learning notes
UE4 source code reading_ Bone model and animation system_ Animation process
Redis data structure
C#课程设计之员工信息管理系统
Installation of PHP FPM software +openresty cache construction
Base64和Base64URL
Constraintlayout's constraintset dynamically modifies constraints
随机推荐
Notes on understanding applets 2022/7/3
C#课程设计之员工信息管理系统
Encoding and decoding of golang URL
【Rust 笔记】07-结构体
ArrayList
数据库应用技术课程设计之商城管理系统
【Rust 笔记】09-特型与泛型
One dimensional array two dimensional array (sort Max insert sort)
Unity Editor Extension - drag and drop
Exe file running window embedding QT window
Unity Editor Extension - event handling
Golang string segmentation, substitution and interception
Dealing with duplicate data in Excel with xlwings
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Flex flexible box layout
Data analysis exercises
Markdown directory generation
Base64编码简介
Three characteristics
What is BFC?