日期:2014-05-20 浏览次数:20866 次
public class TT implements Runnable { private int b = 100; public void m1() { synchronized (this) { try { Thread.sleep(3000); b = 1000; } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("b1 = " + b); } } public void m2() { System.out.println("b2 = " + b); } public void run() { this.m1(); } public static void main (String[] args) throws Exception { TT t = new TT(); Thread t1 = new Thread(t); t1.start(); Thread.sleep(500); t.m2(); } }