Publish: An object is to enable it to be referenced by code outside the current scope:
Common forms: storing references to objects to public static domains; returning references in non-private methods; publishing internal class instances, including references.
Escape: Publish the object when it is not ready.
Don't let this reference escape from the constructor. For example, start a thread in the constructor, and the thread will contain references to the object.
Synchronized container: Performs travel access to all states of the container, Vector, Hashtable, Cllections.synchronizedMap|List
Concurrent containers: ConcurrentHashMap, CopyOnWriteArrayList, ConcurrentLinkedQueue, BlockingQueue
list The advantages of the random access feature.
Blocking adds blockable get set operation
ConcurrentHashMap: Separate locks, bringing high throughput for concurrent access, while losing almost no access performance of a single thread. Returns a weakly consistent iterator.
The weak consistency of the iterator will detect changes in the container after iterator is generated.
The concurrent container size(), isEmpty() is weakened and returns an approximate result.
CopyOnWriteArrayList: Copy every time the container is modified, and the iterative requirement is greater than the modification requirement.
Producer-consumer model, using bounded blocking queues to decouple producers and consumers' code.
Executor task execution framework implements the producer and consumer model.
SynchronousQueue: put waits for the consumer to be available, take waits for the producer to be available, suitable for scenarios where the consumer is sufficient.
A double-ended queue is associated with the work stealing mode. It is different from the fact that all consumers share a work queue in the producer-consumer mode. Each consumer in the work stealing mode has his own double-ended queue. If a consumer completes all his work, he can steal tasks at the end of other consumer queues.
Work Stealing Mode is suitable for when running to a unit of a task, more tasks may be identified, such as traversing files.
When a method can throw an InterruptedException, it means it is a blockable method. Throw or catch InterruptedException.
Synchronizer: synchronizer---semaphore, barrier, latch, encapsulates the state, determines the behavior of the thread in this state (pass or blocks), provides a method to manipulate the state, and efficiently waits for the synchronizer to enter the desired state.
latch lock: Delays the thread progress until the thread reaches an end state, like a one-time switch. Can be used to ensure that a specific activity does not occur until other activities are completed.
For example:
FutureTask can be used as a locking, abstract portable result calculation, and is implemented through callable. Future.get depends on the execution status of the task. If the task is completed, the result will be returned. Otherwise, it will be waiting.
The Executor framework uses FutureTask to complete asynchronous tasks.
semapher semapher: used to control the number of activities that can access a specific resource simultaneously or perform a given operation at the same time, resource pool, container boundary.
barrier level: Similar to locking, all threads must reach the level at the same time before they can continue processing. The locking waits for time, and the level waits for other threads, and is reused. Through the level, await will return a unique arrival index number for each thread, which can be used to elect a leader and undertake some special tasks in the next iteration.
Exchanger is a form of a level.
The above is all the content of this article. I hope that the content of this article will be of some help to everyone’s study or work. I also hope to support Wulin.com more!