private int mInt=1; for (int i = 0; i < 50000; i++) { Thread thread = new Thread(new Runnable() { @Override public void run() { Inner inner = new Inner(); for (int i = 0; i < 10000; i++) { inner.t1(); } } }); thread.start(); } Log.i(TAG, "安全锁测试。。。"+mInt); class Inner { public void t1() { synchronized (this) { mInt++; } } }
为什么每次的结果都不一样,不是同步锁吗???
SynchronizedExp: 安全锁测试。。。499970001
SynchronizedExp: 安全锁测试。。。499890001
SynchronizedExp: 安全锁测试。。。499922095
SynchronizedExp: 安全锁测试。。。499913016
慕仰6620973