1

dumpStackTrace の最初の要素が java.awt.EventDispatchThread.run にあるときに isEventDispatchThread() が false を返すのはなぜですか?

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            doStuff();
        }
    });

    public void doStuff(){
       Thread.dumpStack();
       System.out.print(" [addToParents] "
           + ((SwingUtilities.isEventDispatchThread() 
           ? "out of EDT" : " in EDT ")));
    }

収量:

[addToParents] out of EDT
java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1342)
    at pt.up.fe.dceg.neptus.gui.MissionBrowser.doStuff(MissionBrowser.java:899)
    at pt.up.fe.dceg.neptus.gui.MissionBrowser.access$6(MissionBrowser.java:883)
    at pt.up.fe.dceg.neptus.gui.MissionBrowser$3.run(MissionBrowser.java:1221)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

これは単純化されたコードです (MWS ではありません)。それは私が理解できなかった概念だと思うので、含めませんでした.MWSが必要な場合は教えてください.

4

1 に答える 1

4

いいえ、そうではありません。三項演算子の式で:

(SwingUtilities.isEventDispatchThread() ? "out of EDT" : " in EDT ")))

SwingUtilities.isEventDispatchThread()戻っtrueてきたので、印刷してい"Out of EDT"ます。

式のcondition ? value1 : value2場合:conditionが true の場合、結果は です。value1それ以外の場合、結果はvalue2です。

于 2013-10-29T19:12:03.967 に答える