Overview
Previously, the various classes in the Java collection package were explained in the Java Collection Family Catalog (category). Next, you will expand the collection in the Juc package to learn. Before you learn, review the Java collection package. The contents of this chapter include:
Java Collection Package
collection classes in the Juc
Reprint Please specify source: http://www.cnblogs.com/skywang12345/p/3498454.html
Java Collection Package
In the general framework for Java Collection Series 01, the schema of the Java collection is described. The main content includes the collection collection and the Map class, while the collection collection can be divided into List (queue) and set (collection).
1. List of the main implementation classes are: LinkedList, ArrayList, Vector, Stack.
LinkedList is a double-ended queue implemented by a doubly-linked list; it is not thread-safe and only applies to single-threaded.
(ArrayList) is an array-implemented queue, which is a dynamic array; it is not thread-safe and only applies to single threads.
Vectors are vector queues implemented by arrays, and it is also a dynamic array, but unlike ArrayList, vectors are thread-safe and support concurrency.
Stack is a stack of vector implementations, and, like vectors, it is thread-safe.
2. Set implementation classes are mainly: Hastset and TreeSet.
HashSet is a collection of non-repeating elements that are implemented through HashMap; HashSet is not thread-safe and only applies to single threads.
TreeSet is also a collection of non-repeating elements, but unlike HashSet, the elements in TreeSet are ordered; it is implemented through TreeMap; TreeSet is not thread-safe, only for single-threaded.
The 3.MAP implementation classes are mainly: Hashmap,weakhashmap, Hashtable and TreeMap.
HashMap is a hash table that stores "key-value pairs"; It is not thread-safe and only applies to single threads.
Weakhashmap is also a hash table; Unlike HashMap, HashMap's "key" is a strong reference type, and Weakhashmap's "key" is a weak reference type, meaning that when a key in Weakhashmap is no longer in use, will be automatically removed from the Weakhashmap. Weakhashmap is also not thread-safe and is only available for single-threaded use.
Hashtable is also a hash table; Unlike HashMap, Hashtable is thread-safe and supports concurrency.
TreeMap is also a hash table, but the "key-value pair" in TreeMap is ordered, it is implemented by the R-b tree (red and black); TreeMap is not thread-safe and only applies to single threads.
For more information on these collection classes, refer to the Java Collection series catalog (category).
For convenience, we will refer to the collection classes described previously collectively as "Java Collection packages ." Java collection packages are mostly "non-thread-safe", although the synchronization classes for Java collection packages can be obtained through methods in the Collections tool class, but the concurrency of these synchronization classes is not very high. In order to better support high concurrency tasks, the concurrency guru Doug Lea adds a corresponding high concurrency-enabled class to the single-threaded class in the Java collection package in the Juc (java.util.concurrent) package. For example, the ArrayList corresponding high concurrency class is the copyonwritearraylist,hashmap corresponding high concurrency class is concurrenthashmap, and so on.
The JUC package uses the framework in the Java Collection package when adding a high concurrency class corresponding to the Java collection package, in order to maintain the consistency of the API interface. For example, Copyonwritearraylist implements the list interface in the Java collection package, HashMap inherits the Abstractmap class from the Java collection package, and so on. since the Juc package uses classes from the Java collection package, it is relatively easy to understand the classes in the Juc package if we understand the concepts of the classes in the Java collection package, and the biggest difficulty in understanding it is how to add support for "high concurrency" to the JUC package!
collection classes in the Juc
Below, we first understand the framework of the collection class in the Juc package, and for the sake of speaking, I divide the collection class in the Juc package into 3 parts to illustrate. After a simple understanding of the framework of the collection class in the Juc package, the subsequent chapters introduce each class gradually.
1. List and set
The list and set implementation classes in the Juc collection package include: Copyonwritearraylist, Copyonwritearrayset, and Concurrentskiplistset. Concurrentskiplistset later when explaining the map, the copyonwritearraylist and copyonwritearrayset frameworks are as follows:
Copyonwritearraylist is equivalent to thread-safe ArrayList, which implements the list interface. Copyonwritearraylist is supported for high concurrency.
Copyonwritearrayset equivalent to thread-safe hashset, which inherits from the Abstractset class. The Copyonwritearrayset contains a Copyonwritearraylist object, which is implemented through Copyonwritearraylist.
2. Map
The implementation classes for map in the Juc collection package include: Concurrenthashmap and Concurrentskiplistmap. Their framework is as follows:
Concurrenthashmap is a thread-safe hash table (equivalent to thread-safe hashmap); it inherits from the Abstractmap class and implements the Concurrentmap interface. Concurrenthashmap is implemented through "lock segmentation", which supports concurrency.
(CONCURRENTSKIPLISTMAP) is a thread-safe, orderly hash table (equivalent to thread-safe treemap); It inherits from the Abstractmap class and implements the Concurrentnavigablemap interface. Concurrentskiplistmap is implemented through a "skip table", which supports concurrency.
Concurrentskiplistset is a thread-safe, orderly collection (equivalent to thread-safe treeset); it inherits from Abstractset and implements the Navigableset interface. Concurrentskiplistset is implemented through CONCURRENTSKIPLISTMAP, and it also supports concurrency.
3. Queue
The implementation classes for the queue in the Juc collection package include: Arrayblockingqueue, Linkedblockingqueue, Linkedblockingdeque, Concurrentlinkedqueue and Concurrentlinkeddeque. Their framework is as follows:
Arrayblockingqueue is a thread-safe, bounded blocking queue implemented by an array.
(Linkedblockingqueue) is a one-way linked list (specified size) blocking queue, which sorts elements in FIFO (first-out).
Linkedblockingdeque is a bidirectional concurrent blocking queue (specified size) implemented by a doubly linked list that supports both FIFO and filo two modes of operation.
Concurrentlinkedqueue is an unbounded queue implemented by a one-way list, which sorts elements in FIFO (first-out).
Concurrentlinkeddeque is an unbounded queue implemented by a doubly-linked list that supports both FIFO and filo two modes of operation.
Next, you will learn about the collection classes in the Juc package one by one.
Java multithreaded class: Juc collection: Frame of 01