java thread memory model of eight kinds of actions:
read (Read): Read data from main memory
load (Load): Data read from the main memory are loaded into memory the working
use (use): Use the number of working memory
assign (assignment): If a thread of shared variables to make a change, the new data is written to the work area
store (): the changed data back to the work area to re-write main memory
write (write): the main variables in memory to re-assign a new value.
lock (lock):
unlock (unlock):
Jvm cache solve the problem of inconsistency:
Bus lock: low performance, since the locking mechanism through the bus, parallel execution will eventually ended up multicore cpu serial execution, since the lock and unlock
MESI cache coherency protocol: multiple cpu back from a main memory to read data to the respective cache When a thread to make changes to the data, will immediately synchronize main memory, cpu by other bus sniffing mechanism can be perceived data changes so that their data cache failure, MESI cache coherency protocol only when written back to main memory plus lock lock, size is very small.
Due to the use of variables in the thread, each thread will have their own copy of the variable, so that when data changes in one thread and the other thread does not know the data conversion, while the Volatile solve the visibility of data
Concurrent three characteristics: visibility, atomicity, ordering
Volatile: bottom layer is achieved by prefix instructions lock assembly language, to solve the shared variables among efficiency multithreaded visibility, does not guarantee atomicity radiolabeling, reduced volatile program will not replace Synchronized