//这个线程可以退出的原因是什么
public class Test {
public static boolean flag = true;
public static volatile boolean stop = false;
public static void main(String[] args) throws InterruptedException {
Runnable runnable = () -> {
while (flag != stop){
}
System.out.println("结束");
};
new Thread(runnable).start();
Thread.sleep(2000);
flag = false;
}
}
volatile可见性问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-