package com.aflfte.others;
/**
* Volatile的使用
* 保证数据的同步,也就是可见性
*
* @author jinhao
*
*/
public class VolatileTest {
private volatile static int num=0;
public static void main(String[] args) throws Exception {
new Thread(()->{
while(num==0) {
}
}) .start();
Thread.sleep(1000);
num=1;
}
}
« DCL单例模式
|
指令重排测试»
|