public class 可见性 {
public static boolean falg = false;
public static void main(String[] args) throws InterruptedException {
new Thread(() -> {
while (!falg) {
// Thread.sleep(1);
// File file =new File("D:\\IdeaProjects\\Open-Web\\Branches\\order_rebuild");
// System.out.println("s");
}
}).start();
Thread.sleep(200);
falg = true;
System.out.println("thread");
/*
Thread.sleep(1); // 线程有空闲时间,会重新从主存中刷新数据
//IO操作线程切换 ,切回来时会重新从主存中读取数据
File file =new File("D:\\IdeaProjects\\Open-Web\\Branches\\order_rebuild");
//设计到获取锁会强制重新读取数据
System.out.println("s");
这三中操作都会使线程结束
*/
}
}