java同步synchronized volatile仅仅用来保证该变量对所有线程的可见性,但不保证原子性. 看下面的这段代码: /** * * @author InJavaWeTrust * */ public class CountVolatile implements Runnable { public static CountVolatile instance = new CountVolatile(); public static volatile int i = 0; public…