public class SynchronizedTest implements Runnable { private Integer i = new Integer(1); public void a(Integer i) { synchronized (i) { i = new Integer(2); try { Thread.sleep(5000); } catch (Exception e) { } System.out.println("a() i = " + i); } } public void b() { System.out.println("b() i =" + i); } public void setI(Integer i) { this.i = i; } public void run() { a(i); System.out.println("a()---------------"); } public static void main(String[] args) { SynchronizedTest st = new SynchronizedTest(); Thread t = new Thread(st); t.start(); try { Thread.sleep(1000); } catch (Exception e) { } st.b(); st.setI(5); } } 关于synchronized(obj)