volatile 验证 java
package interview; public class VolatileTest implements Runnable { private volatile boolean isRun = true; @Override public void run() { System.out.println("run start"); while(isRun){ } System.out.println("run end"); } public void setRun(boolean isRun) { this.isRun = isRun; } public static void main(String[] args) throws Exception { VolatileTest vt = new VolatileTest(); new Thread(vt).start(); Thread.sleep(2000); vt.setRun(false); } }