A simple summary of the Java memory model

Source: Internet
Author: User

First, the basic
problem : How to communicate between threads and how threads are synchronized.
Communication: How information is exchanged between multiple threads.
Means of communication: Shared memory (implicit) and message passing (explicit).
The corresponding concurrent programming model has two kinds: concurrent programming model of shared memory and concurrent programming model of message passing.
Synchronization: A mechanism for controlling the relative order of operations between different threads.
There are also synchronization and implicit synchronization shown.
The concurrent programming model for shared memory requires a display synchronization.
The concurrent programming model for message passing is synchronized implicitly.
Concurrent programming model for shared memory used by the Java Concurrency programming model.
Second, JMM
question : How does a thread in Java deliver a message?
Java heap memory is shared between threads, and the stack is not.
Instance fields, static fields, and arrays are all stored in the heap. called Shared variables.
JMM controls when a thread writes a shared variable to another thread when it is visible.
The following describes the relationship between local memory and main memory in the thread:
The shared variables in the thread are stored in main memory.
Each thread has a private local memory, and local memory is an abstraction that includes caching, write buffers, registers, other hardware, and compiler optimizations.

Steps for thread A and B communication:
1. Thread A first flushes a copy of the shared variable that may have changed locally into main memory.
2, then thread B reads the variable from main memory, and then updates the copy of its own variable.

  从今天开始跑,加速度的跑、不要回头、当速度足够块的时候,你将看到一些你从未看到过的风景。                  --安藤忠雄

A simple summary of the Java memory model

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.