Java Multi-thread queue

Source: Internet
Author: User

1. Note: If you do not see blocking or not, this reentrantlock use means that this class is a thread-safe class.

2. Thread-safe classes, blockingqueue,concurrentlinkedqueue. These are thread-safe collection classes

In Java multithreaded applications, queue usage is high, and the preferred data structure for most production consumption models is the queue. Java provides a thread-safe queue that can be divided into blocking queues and non-blocking queues, where a typical example of a blocking queue is blockingqueue, a typical example of a nonblocking queue is concurrentlinkedqueue, In practical application, we should choose the blocking queue or non-blocking queue according to the actual need.

Note: What is thread safety? This must be clear first. Thread-safe classes, which refer to the access of shared global variables within a class, must be guaranteed to be unaffected by the form of multithreading. This class is not thread-safe if the structure of these variables is corrupted due to multi-threaded access (such as modification, traversal, viewing) or if the atomicity of these variable operations is compromised.
Talk about these two types of queue today, this article is divided into the following two sections, separated by dividing lines:

    • Blockingqueue Blocking algorithm
    • Concurrentlinkedqueue, non-blocking algorithm

Java Multi-thread queue

Related Article

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.