In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about the order of the Java memory model. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
The definition of orderliness: the order in which the program is executed according to the order of the code.
In JMM, there are three ways to ensure orderliness:
Happens-before principle synchronized mechanism volatile mechanism
Happens-before principle
The happens-before principle is the partial order relationship between the two operations defined in the Java memory model. If operation An occurs first in operation B, it means that the effect of operation A can be observed by operation B before operation B. "influence" includes modifying the value of shared variables in memory, sending messages, calling methods, and so on.
Here are some "natural" preemptive relationships under the Java memory model, which already exist without any synchronizer assistance and can be used directly in coding. If the relationship between two operations is not in this list and cannot be derived from the following rules, they are not guaranteed to be sequenced, and the virtual machine can reorder them at will:
Program order rules (ProgramOrderRule): within a thread, according to the order of the program code, the operation written in front occurs first in the operation written later. To be exact, it should be to control the flow order rather than the program code order, because branches, loops, and other structures should be considered.
Pipe locking rule (MonitorLockRule): a unlock operation occurs first in a subsequent lock operation on the same lock. What must be emphasized here is the same lock, and "after" refers to the chronological order.
Volatile variable rule (VolatileVariableRule): the write operation to a volatile variable occurs first in the subsequent read operation on the variable, and the "after" here also refers to the chronological order.
Thread startup rule (ThreadStartRule): the start () method of the Thread object occurs first in every action of this thread.
Thread termination rule (ThreadTerminationRule): all operations in a thread first occur in the termination detection of this thread. We can detect that the thread has terminated execution by means such as the end of the Thread.join () method and the return value of Thread.isAlive ().
Thread interrupt rule (ThreadInterruptionRule): the call to the thread interrupt () method first occurs when the code of the interrupted thread detects the occurrence of the interrupt event, and the interrupt event can be detected by the Thread.interrupted () method.
Object termination rule (FinalizerRule): the initialization of an object (the end of constructor execution) occurs first at the beginning of its finalize () method.
Transitivity (Transitivity): if operation An occurs first in operation B and operation B occurs in operation C first, then it can be concluded that operation An occurs first in operation C.
The above is the order of the Java memory model shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.