当 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,请告诉我。