volatile的例子
package player.kent.chen.learn.hivolatile; /** * 循环直到有人喊停 */ public class LoopUntilCommand { private boolean stop; /** * 循环直到有人喊停 */ public void loop() { while (!stop) { ; } System.out.println("Stopped because somebody said so"); } /** * 喊停 */ public void sayStop() { stop = true; } public static void main(String[] args) throws InterruptedException { final LoopUntilCommand luc …