2014-01-24 59 views
0

當我跑我在樹莓派程序,我得到這個從日誌:儘管runLater有兩個AWT線程?

[THREAD ID=AWT-EventQueue-2]24 Jan 2014 12:56:21 DEBUG PFrameClient - 2 - performAnimation 
[THREAD ID=AWT-EventQueue-1]24 Jan 2014 12:56:24 DEBUG PFrameClient - 3 - entering onAnimationFinished 
[THREAD ID=AWT-EventQueue-2]24 Jan 2014 12:56:24 DEBUG PFrameClient - 1 - entering performAnimation 
[THREAD ID=AWT-EventQueue-1]24 Jan 2014 12:56:24 DEBUG PFrameClient - 4 - leaving onAnimationFinished 

...但所有做記錄的代碼被包裹在SwingUtilities.invokeLater電話(見下文)。

在Mac和Windows上,所有調用都記錄爲在一個線程中。

有人能告訴我,並幫我弄清楚有什麼問題嗎?

(在onAnimationFinished定時器用於避免死鎖的情況)

public void performAnimation(final Animation animation) throws RemoteException { 
    final Animation.Observer obs = this; 
    SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 
      logger.debug("1 - entering performAnimation"); 
      animation.perform(world, obs); 
      logger.debug("2 - performAnimation"); 
     } 
    }); 
} 

public void onAnimationFinished(final int tag) { 
    final Timer t = new Timer(); 
    final TimerTask r = new TimerTask() { 

     @Override 
     public void run() { 
      SwingUtilities.invokeLater(new Runnable() { 
       public void run() { 

        logger.debug("3 - entering onAnimationFinished"); 


        templateMethodOnAnimationFinished(tag); 
        try { 
         master.animationIsFinished(tag); 
        } catch (RemoteException e) { 
         throw new RuntimeException(e); 
        } 
        logger.debug("4 - leaving onAnimationFinished"); 
        logger.debug("----"); 
       } 
      }); 

     } 

    }; 
    t.schedule(r, 100); 
} 

回答

0

Aaaaaaand這是因爲原來的Swing框架不使用invokeLater的Swing的主線程上創建的。

TIL總是檢查我的程序的主要方法,當爲Swing編碼時。