One, synchronous container
The main representatives are vectors and Hashtable, and collections.synchronizedxxx and so on.
The granularity of the lock is the whole of the current object.
An iterator is a timely failure that, when found to be modified during an iteration, throws a concurrentmodificationexception.
Second, concurrent containers
The main representatives are Concurrenthashmap, Copyonwritearraylist, Concurrentskiplistmap, Concurrentskiplistset.
The granularity of the lock is scattered, fine-grained, that is, the read and write are used with different locks.
Iterators have weak consistency and can tolerate concurrent modifications without throwing concurrentmodificationexception.
Third, blocking the queue
The main representatives are Linkedblockingqueue, Arrayblockingqueue, Priorityblockingqueue (Comparable,comparator), Synchronousqueue.
provides a blocking put and take method, as well as support for timed offer and poll methods.
Suitable for producer, consumer mode (thread pool and Work queue-executor), but also synchronous container
Four, two-terminal queue
The main representatives are Arraydeque and Linkedblockingdeque.
meaning: Just as the blocking queue applies to the producer consumer model, the double-ended queue also works with another mode, that is, work-out. In producer-consumer design, all consumers share a single task queue, while in a work-in-process, each consumer has its own double-ended queues.
If a consumer completes all the work in his own double-ended queue, he can get a secret job from the end of the other consumer's double-ended queue. Have better scalability, because worker threads do not compete on a single shared task queue .
Most of the time, they are simply accessing their own double-ended queues, which greatly reduces competition. When a worker thread needs to access another queue, it gets work from the tail of the queue instead of the head, thereby further reducing contention on the queue.
Applies to: Web crawler and other tasks
Synchronization containers, concurrent containers, blocking queues, double-ended queues