In understanding what is Java memory model before, first look at why the proposed Java memory model.
Concurrent programming mentioned before there are three major problems
- CPU cache, in the case of multi-core CPU, brings visibility problems
- Operating system to switch the current thread of execution, bringing the atomic issue
- Translation directive rearrangement optimization, bringing orderliness issues
In order to solve the three problems of concurrent programming, proposed JSR-133, the new Java memory model, JDK 5 started.
So what is the Java memory model it?
Now that the Java memory model, generally refers to JSR-133: Java Memory Model Java Memory Model and Thread Specification Revision provisions.
JSR-133 specific description: jsr133.pdf
JSR-133 specifically described in the official website of the JCP
Under instructions
JSR: Java Specification Requests, Java specification proposal.
JCP: Java Community Process is an open international organization, established in 1998, consists of Java developers and those who are authorized to make up, is to make interested parties to participate in the definition of Java features and future versions of the official process.
Under a brief summary
- Java memory model is a specification of JVM
- Specification defines the behavior of shared memory read and write operations in a multi-threaded programs
- Blocked access to a variety of hardware and operating system differences, ensuring consistent access to the Java program's effect on memory in a variety of platforms
- Way to solve concurrency issues adopted: to limit the use of memory and processor optimization barrier
- Three enhanced synchronization primitives (synchronized, volatile, final) semantic memory
- Defines happens-before rule
参考:
1、https://baike.baidu.com/item/JSR
2、https://baike.baidu.com/item/JCP
3、https://zh.wikipedia.org/zh-hans/JCP
Java interview questions summary, there is always a stuck you!