Lock-Free is an optimistic strategy that uses CAS (compare and swap) to identify thread conflicts and, if a conflict occurs, retries the current operation until there is no conflict.
CAS (v,e,n) V variables to be updated, E for expected values, N for heart values
V is set to n only when V=e is present if v!=e indicates that another thread has made updates to the current thread and does nothing
CAS operations can find other threads interfering with the current thread and handle it appropriately, even without a lock.
Atomicinteger
#final boolean compareandset (int expect, int u)//If the current value is expect set to u
Compareandset----> Unsafe.compareandswapint (objuect obj,long valueoffset,int expect,int Update)
Static fields are not supported
in fact, CAS is also a lock operation, but is triggered by the CPU, more than the synchronized performance better . ---http://www.jianshu.com/p/9f0ba2bab24e
Your application cannot use the unsafe class it is a proprietary class used inside a JDK
Atomicreference//Guaranteed thread safety when modifying object references
Atomicstampedreference//Apply to "one-time modification" at this point, it is not only more than the value of the time stamp
Atomicintegerarray Atomiclongarray Atomicreferencearray
Atomicintegerfieldupdater
Using the reflection mechanism
Variables need to be defined as volatile and cannot be private static type
Java Multi-threaded---no lock