Java Foundation---Multithreaded---java memory model

Source: Internet
Author: User
===java the role of the memory model. The Java memory model defines the abstract relationship between threads and threads and the main memory. Each thread has its own area of memory, which is a copy of the variable copied from the main memory, which is an abstract concept.  The communication between threads is flushed through main memory, and the modified data is refreshed to the main memory, which is available to other threads. = = = Considering that the memory model cannot escape the command reordering in order to improve performance, the compiler and the processor will do the command reordering. Command reordering follows a set of rules in single-CPU and single-threaded conditions: 1. If you have data dependencies such as write-and-read first, read and write again, do not reorder; When you control dependencies, you cache the results of the calculations and then wait for the criteria to be judged. A = 1;b = 1;bool = True;c = a + b; if (bool) {c = a * A;} 2. Ensure that the results are not changed in the case of reordering. command reordering in the case of multithreading, memory visibility issues may occur if you do not synchronize. Happens Beforejava provides programmers with an easy-to-manipulate reordering rule, which is happens before rules. He is a rule that represents visibility, such as a happens before B, which indicates that a's execution result is visible to B, but does not require a to be executed before B. Each happens before rule corresponds to a series of reordering rules at the bottom, and we don't need to know how the underlying is reordered, equivalent to providing us with a set of rules that make it easier to understand the order reordering.

Java Foundation---Multithreaded---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.