Java thread concurrency: knowledge point, java thread knowledge point

Source: Internet
Author: User

Java thread concurrency: knowledge point, java thread knowledge point
Java thread concurrency: knowledge point release: an object is used to make it be referenced by code out of the current range. Common form: store the reference of an object to a public static domain; A reference is returned in a non-private method. An internal class instance is released, including a reference. Escape: publish an object before it is ready. Do not let this reference escape from the constructor. For example, to start a thread in the constructor, the thread will contain object references. Synchronous container: access all container statuses, including Vector, Hashtable, Cllections. synchronizedMap | List concurrent containers: ConcurrentHashMap, CopyOnWriteArrayList, concurrentincluqueue, and BlockingQueue list. Blocking adds the blocked get set operation ConcurrentHashMap: The separation lock, which brings high throughput for concurrent access, and almost no loss to the access performance of a single thread. An iterator that returns weak consistency. The weak consistency of the iterator is detected after the iterator is generated. Concurrent container size (), isEmpty () is weakened, and approximate results are returned. CopyOnWriteArrayList: copy each time a container is modified. The applicable iteration requirement is greater than the modification requirement. The producer consumer model decouples the producer and consumer code using a bounded blocking queue. The Executor task execution framework implements the producer and consumer mode. SynchronousQueue: put waits for the consumer to be available and take waits for the producer to be available. It is suitable for scenarios where the consumer is sufficient. Deque is associated with the work stealing mode. Different from the consumer mode, all consumers share a work queue. In the work stealing mode, each consumer has its own two-end queue, if a consumer completes all his work, he or she can steal the tasks at the end of other consumer queues. The work theft mode is applicable to identifying more tasks, such as traversing files, when a task is running to a certain unit of a task. When a method can throw InterruptedException, it indicates that it is a blocking method. Throw or capture InterruptedException. Synchronizer: The Synchronizer-semaphore, barrier, and latch. It encapsulates the state and determines the action (through or blocking) of the thread in this state. It provides a method to control the state, efficient waiting for the synchronization to enter the desired state. Latch locking: delays the thread progress until the thread reaches an end state, like a one-time switch. It 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 blocking and abstract computation of portable results, which is implemented through callable. Future. get depends on the execution status of the task. if the task is completed, the result is returned. Otherwise, the Executor framework uses FutureTask to complete the asynchronous task. Semapher semaphores: used to control the number of activities that can access a specific resource at the same time or the number of operations that can be performed at the same time, resource pools, container boundaries. Barrier level: similar to locking. It is different that all threads must reach the level at the same time to continue processing. Locking waits for time, And the level waits for other threads for reuse. Through checkpoints, await returns a unique index number for each thread. It can be used to elect a lead and undertake some special tasks in the next iteration. Exchanger is a level.

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.