public class Demo1 { private static boolean initFlag=false; public static void main(String[] args) throws InterruptedException { new Thread(new Runnable() { @Override public void run() { System.out.println("waiting data......"); while (!initFlag
用volatile修饰的变量,线程在每次使用变量的时候,都会读取变量修改后的最新的值.volatile很容易被误用,用来进行原子性操作. package com.guangshan.test; public class TestVolatile { public static int count = 0; public static void inc () { try { Thread.sleep(1); } catch (Exception e) { } count++; } public s