119

volatile关键字的作用、原理

 6 years ago
source link: https://juejin.im/post/59db333b6fb9a00a69752a39
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
在只有双重检查锁,没有volatile的懒加载单例模式中,由于指令重排序的问题,我确实不会拿到两个不同的单例了,但我会拿到“半个”单例。 而发挥神奇作用的volatile,可以当之无愧的被称为Java并发编程中“出现频率最高的关键字”,常用于保持内存可见性和防

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK