1. Java Memory model

Source: Internet
Author: User

In Java, all instance, static, and array elements are stored in heap memory, and heap memory is shared between threads. Local variables, method definition parameters, and exception handler parameters are not thread-

Shared between them, they will not have memory visibility issues and are not affected by the memory model.

Communication between Java threads is controlled by the Java Memory Model (JMM), and JMM determines when a thread's write to a shared variable is visible to another thread. From an abstract point of view, JMM

Defines the abstract relationship between the thread and the main memory: Shared variables between threads are stored in main memory, and each thread has a private local memory (local memory), where the thread is stored in a copy of the read/write shared variable. Local memory is an abstract concept of JMM and is not really there. It covers caching, write buffers, registers, and other hardware and compiler optimizations. The Java memory model is abstracted as follows:

From the view, if you want to communicate between thread A and thread B, you have to go through the following 2 steps:

1. First, thread a flushes the updated shared variables in local memory A to the main memory.

2. Then, thread B to main memory fetches the shared variable that was updated before thread A.

1. 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.