public class VolatileVisible {
boolean running = true; //
void m() {
System.out.println(“m start”);
while(running) { //
}
System.out.println("m end");
}
public static void main(String[] args) {
VolatileVisible vt = new VolatileVisible();
new Thread(vt::m,"t1").start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
vt.running = false;
}
}