Chapter One concurrency classes common to Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.