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