Container mind mapping
Container development process
Vector – > Queue
1. Jdk1.0 starts with Vector and HashTable, The underlying use Synchronized 2. ArrayList HashSet thread unsafe version 3. Collections. Synchronized * * * the underlying also USES Synchronized 4. ConcurrentLinkedQueue Cas is used at the bottomCopy the code
HashTable – > ConcurrentHashMap
1) HashTable using Synchronized bottom (2) a HashMap thread unsafe 3. Collections. SynchronizedMap, Synchronized 4 is used at the bottom level.ConcurrentHashMap is used at the bottom levelCopy the code
Using early synchronous container and Collections. SynchronizedXXX method’s shortcomings
Only one thread can access a method at a time. 2. Some methods call other methods internally. For example, iteration or putIfAbsent. If another thread inserts or deletes an iteration, concurrent modification exceptions will occur. PutIfAbsent calls putVal(Hash (key), key, value, true, true).Copy the code
The main container in the Queue
- Queue was added after jdk1.5 to handle containers with high concurrency.
CocurrentLinkedQueue
The bottom layer is a linked list container that uses the lock-free operation of CASCopy the code
Deque
Double - ended linked list, can implement stack and queueCopy the code
BlockingQueue
Block queue - changed interface to put() and take()Copy the code
BlockingQueue source
SynchronusQueue
No buffered blocking queueCopy the code
SychronousQueue source code parsing
3.TransferQueue
The TransferQueue tries to match the head first, and inserts the end if the match fails. Compared to SychronousQueue more cache queue, compared to BlockingQueue can directly pass elements TransferQueue source code
DelayQueue
DelayQueue is an implementation class of BlockingQueue, which uses PriorityQueue and leader-follower modes. DelayQueue source