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

大家来参与下!
同志们,下面这段代码在你们机器上输出什么?请亲自测试后再回复!!
Java code
public class Test{
    private static boolean ready;
    private static int number;
    
    private static class ReaderThread extends Thread
    {
        public void run()
        {
            while(!ready)
            {
                Thread.yield();
            }
            System.out.println(number);
        }
    }
    /**
     * @param args
     * @throws InterruptedException 
     */
    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        new ReaderThread().start();
        Thread.sleep(1000);
        number = 42;
        ready = true;
    }

}


------解决方案--------------------
42 
正好开着eclipse,没看程序直接运行的结果
------解决方案--------------------
42呀!!!!不对吗
------解决方案--------------------
我也是42,正好开着STS

------解决方案--------------------
输出:42