[Java Concurrent Programming] understand volatile keyword from CPU cache model to JMM

Three characteristics of concurrent programming

Atomicity

For one operation or multiple operations, either all operations are executed and will not be interrupted by any factors, or all operations are executed or not executed.

For access to basic data types, both reading and writing are atomic [long and double may be exceptions].

If you need a wider range of atomicity guarantees, you can use the synchronized keyword.

visibility

When a variable modifies a shared variable, other threads can immediately see the latest modified value.

volatile@H_404_80 @In addition to ensuring the visibility of shared variables, synchronized@H_404_80 @And final@H_404_80 @Visibility can be achieved.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>