package com.aoptest.test;
import java.util.Date;
public class ProblemDemo {
/*volatile*/ boolean flag = true;
void test() {
System.out.println("start");
while (flag) {
System.out.println(".");
}
System.out.println("end");
}
public static void main(String[] args) throws InterruptedException {
ProblemDemo problemDemo = new ProblemDemo();
new Thread(problemDemo::test).start();
Thread.sleep(1000);
problemDemo.flag = false;
System.out.println("main end ");
}
}
这个问题有人问过R大,去知乎看看R大的回答吧