日期:2014-05-20 浏览次数:20986 次
public class TestThread { static int aa = 0; public static void main(String[] args) { Threadd a = new TestThread().new Threadd(); Threadd b = new TestThread().new Threadd(); Threadd c = new TestThread().new Threadd(); a.start(); b.start(); c.start(); } class Threadd extends Thread { @Override public void run() { printt(); } } // 为什么这个地方不能锁定呢? synchronized void printt() { this.aa = (this.aa + 1); System.out.println(this.aa); } }
public class TestThread { static int aa = 0; public static void main(String[] args) { Threadd a = new TestThread().new Threadd(); Threadd b = new TestThread().new Threadd(); Threadd c = new TestThread().new Threadd(); a.start(); b.start(); c.start(); } class Threadd extends Thread { @Override public void run() { printt(); } } // 为什么这个地方不能锁定呢? static synchronized void printt() { //synchronized (TestThread.class) { aa = (aa + 1); System.out.println(aa); //} } }