Runnable r = new Runnable(){
public void run(){
System.out.print("Gaston.");
}
};
SwingUtilities.invokeLater(r);
try{sleep(1000);}catch(Exception ex){}
System.out.print("Alphonse."); Runnable r = new Runnable(){
public void run(){
System.out.print("Gaston.");
}
};
try{
                        SwingUtilities.invokeAndWait(r);
                        sleep(1000);
                }catch(Exception ex){}
System.out.print("Alphonse.");这两段代码的输出有如下选择(第一题是多选,第二题是单选):
A. Gaston.
B. Alphonse.
C. Gaston.Alphonse.
D. Alphonse.Gaston.能告诉一下解题思路么?

解决方案 »

  1.   

    这个就是多线程的分发程序
    输出Gaston停一秒后再输出Alphonse
      

  2.   

    没使用过SwingUtilities这类,上网查了一下发现invokeAndWait锁定调用它的线程,那么第二段代码应该是输出Gaston.Alphonse.第一段代码不锁定,那么可能输出Gaston.Alphonse. 也可能输出Alphonse.Gaston.,但是后者一般不可能输出。因为在主线程要睡眠1s,这个过程中新线程肯定已经执行完毕了。
      

  3.   

    第一個是兩個都有可能
    第二個是gaston