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