Java concurrency-related content

Source: Internet
Author: User

1. Vilatile, lock and atomic operations

These three are the basis for understanding Java concurrency.

In simple terms, Vilatile modified variables can ensure that all threads are visible to them, and that the mechanism is actually dependent on atomic operations;

Locks, mainly divided into biased locks, light-weight locks and heavy-lock, resource consumption is also increasing. Using Java's synchronized keyword or a new lock usage, all of these three types of locks are chosen, jdk6 after the default preference to use a bias lock, you can also close the bias lock by Usebaisedlocking=false. The use of biased locking, one is objective fact, usually the same thread to acquire the lock, the other is to consider whether an application has a large number of lock competition. How to implement a lock within a specific JVM can be found in the information about concurrent books.

Atomic operation, the CPU in two ways to ensure that the operation is atomic, one is to lock the bus, inefficient, lock the data bus, other CPUs can not read or write to it; one is to use the CPU's L1,L2,L3 cache (read the relevant data into the cache and then use the CAS algorithm to ensure atomicity). In some cases, the data spans more than one row, or you can modify multiple data at the same time, or you might want to lock the bus for implementation.

The return header says that the implementation mechanism of Vilatile, which is atomic, notifies other CPUs concerned about the value change to update their caches.

Java concurrency-related content

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.