public class ThreadTest {
static boolean flag = false;//非volatile变量
public static void main(String[] args) throws Exception {
new Thread(() -> {
while (!flag) {
}
}).start();
Thread.sleep(1000);
flag = true;
System.out.println("主线程运行完毕");
}
}