Note: This series of blogs mainly refer to "Distributed Java Application: Foundation and Practice", Lin Hao went
1. Common Concurrent Collection classes
- Concurrenthashmap: Implementation of thread-safe hashmap
- Copyonwritearraylist: Thread-safe and ArrayList with no locks during read operations
- Copyonwritearrayset: Based on copyonwritearraylist, do not add duplicate elements
- Arrayblockingqueue: Array-based, first-out, thread-safe for blocking read and write at a specified time, and capacity can be limited
- Linkedblockingqueue: Based on the chain list implementation, read and write each with a lock, in high concurrent read and write operations are more than the case, performance is better than arrayblockingqueue
2. Atomic class
- Atomicinteger: Thread-safe integer, CAS (non-blocking, CPU primitive), better than integer using Sync lock
3. Thread pool
- Threadpoolexecutor: An efficient thread pool to support concurrency, it is easy to tell a implementation of the Runnable interface task into the thread pool execution, but to use this thread pool, you must reasonably configure the corepoolsize, the maximum number of threads, the task buffer queue, And the rejection strategy when the queue is full of + line Cheng, generally there are two types of requirements to consider when configuring these parameters: High performance and buffered execution .
- Executor: Provides some convenient ways to create a threadpoolexecutor.
- Futuretask: Can be used to asynchronously get execution results or cancel the execution of a task, based on CAs, to avoid the use of locks
4. Lock
- Reentrantlock: consistent with synchronized effect, but more efficient , requires manual release of the lock, based on Abstractqueuesynchronizer
- Reentrantreadwritelock: It has nothing to do with Reentrantlock, two locks are used to read more and write less cases.
Note: In this series of blogs, the above classes will focus on the following aspects to record:
- Usage
- SOURCE Interpretation
- Usage Scenarios
- Some of the necessary comparisons
Chapter One concurrency classes common to Java