日期:2014-05-20  浏览次数:20653 次

求助,这个程序为什么只执行了一步,打印了第二个方法,第一个是没执行还是没打印。
Java code

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();
        
        }

    }




------解决方案--------------------
TestSync2 ts = new TestSync2();
Thread tst = new Thread(ts);
tst.start();
f2();
....