日期:2014-05-20 浏览次数:20689 次
public class TestSync2 implements Runnable{ int b = 0; public synchronized void f1(){ try{ Thread.sleep(1000); } catch (InterruptedException ie){} int b = 1000; System.out.println("B1 = " + b); } public static void f2(){ try{ Thread.sleep(500); } catch (InterruptedException ie){} int b = 2000; System.out.println("B2 = " + b); } public void run(){ f1(); } public static void main(String[] args){ TestSync2 ts = new TestSync2(); Thread tst = new Thread(); tst.start(); f2(); } }