Commonly used containers are list, queue, set, map
List has ArrayList, LinkedList, there is a copyonwritearraylist;
The queue has LinkedList, Arrayqueue, Linkedblockingqueue, Concurrentlinkedqueue;
Map has HashMap, TreeMap, Concurrenthashmap, Concurrentskiplistmap;
Set internal general will use map to do storage, there are HashSet, TreeSet, Copyonwritearrayset, Concurrentskiplistset;
Previously introduced Concurrenthashmap, the map because of the need for resize, so need to lock mechanism, and lock granularity is large; Blocking series because of the need to wait, notify operation, so also need to lock mechanism The Concurrentlinkedqueue is a complete CAS operation.
List
ArrayList is an array in which the insertion element may involve expansion, element movement, which may involve element movement when deleted, and if the deletion is only inserted at the end of the list, no element movement is involved, and its advantage is random access.
LinkedList is a linked list, each time the insertion element will create a new node of the element, and then put into the list, compared with ArrayList, the advantage is that the INSERT, delete operation will not involve the element movement, only refers to the changes before and after, there is no expansion problem, The list theory can be infinitely large (the actual length cannot exceed integer.max_value and is limited by the JVM heap space).
Copyonwritearraylist is an array that differs from ArrayList in that Copyonwritearraylist creates a new array before the update operation (the array size is exactly the same as the old and new elements), and then updates the new array. The old array is finally replaced, and the entire update process is locked (reentrantlock), which is thread-safe. As can be seen, the performance of the Copyonwritearraylist update operation is not generally poor, but its advantage is that iterator is completely secure, because the update operation is always done on a new array, and the iterator operation is always an old array, But also because the iterator operation is an old array, Copyonwritearraylist's iterator does not provide an update operation (such as remove).
Queue
Arrayqueue is more efficient than ArrayList because it restricts update element operations to the ends of the array, eliminating the need to move the elements when inserting deletes (which still involves expansion when inserted).
LinkedList not only implements the list interface, but also implements the queue, deque (double ended queue) interface.
Linkedblockingqueue provides a blocking bidirectional queue that can be implemented when the queue is empty, waiting for full, non-empty, non-full-time wake-up, which is achieved through reentrantlock+condition, That is, Linkedblockingqueue is thread-safe (although linkedblockingqueue is a chained structure, it provides capacity settings in the constructor, the default capacity is Integer.max_value).
Concurrentlinkedqueue provides a thread-safe queue implementation, unlike Linkedblockingqueue, where Concurrentlinkedqueue does not use a locking mechanism, using CAS mechanisms, which can greatly improve concurrency.
Map
HashMap hash table is an array, the way to resolve the hash conflict is linked list or red-black tree (JDK8).
TreeMap is a red and black tree.
The CONCURRENTHASHMAP structure is similar to the HashMap, and thread safety is achieved by adding locks on the bucket.
Concurrentskiplistmap uses the Jump table, the physical structure of the jump table is a multi-level linked list, the logical structure is a tree, compared with Concurrenthashmap, Concurrentskiplistmap is the most important feature is the order of key.
Set
Copyonwritearrayset wrapped the Copyonwritearraylist,copyonwritearrayset Add method is Copyonwritearraylist Addifabsent method, is also thread-safe.
Java Basics-Container Brief