Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Two-sentence Notes-- one of Architecture Learning: concurrent basic courses (1)

Shulou Source: shulou.com Published: 2022-06-03 02:42:53 09月11日 Update

1.ConcurrentModificationException

The reason for this is that the elements in the container are modified while traversing (iterator or enhanced loop) the synchronization class container, which can be solved with a normal for loop. Because a normal for loop is a thread operation.

two。 If a normal container wants to become a thread-safe container, it can be done with the Collections.synchronizedCollection method.

The 3.concurrentHashMap is divided into 16 segment slices, which calculates the volitile modification used in the size, while the value, and assignment, is to add a lock in each segment and no lock between the segment.

4.copyonwrite is copied in the data of the original thread every time a write operation is performed. After the operation is completed, the newly modified data will be assigned back, which is not suitable for scenarios with more list elements. When modified at the same time, there is a lock.

5. Various queues, blocking queues, non-blocking queues and × × queues, bounded queues. × × queue, add and offer have the same function. Blocking queue, the exception is not reported when add is added, and false is returned if offer is not added, or the waiting time can be set. The put method blocks right there. The poll method returns if it has a value from the opponent, and the substance returns a failure. The take method, when it has no value, blocks there until it has a value. DrainTo, one-time acquisition of multiple elements to improve efficiency.

6.concurrentLinkQueue is based on non-blocking × × queue, poll, value removal, peek, and values are not removed.

7.ArrayBlockingQueue is based on blocking bounded queues.

8.linkedblockingqueue blocks the queue.

9.SynchronousQueue cannot prevent blocking queues of any elements.

10.ProrityBlockingQueue, when adding, there is a dichotomy algorithm, and when taking a value, there is a comparison algorithm to take out the one with the highest priority.

11.DelayQueue has getDelay method and compareTo method, which are used to set delay time and compare and sort elements.

Tags: Queues blocking methods elements containers normal time threads loops between at the same time data time algorithms highest security one-time priority action reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei Shulou Information Redmi OPPO Reno