更新时间:2021-12-04 22:38:08
从Swing教程中的事件调度线程
From the section in the Swing tutorial titled The Event Dispatch Thread
某些Swing组件方法已标记API规范中的线程安全这些可以从任何线程安全地调用。必须从事件分派线程调用所有其他Swing组件方法。忽略此规则的程序大部分时间可能正常运行,但会受到难以复制的不可预知的错误的影响。
我总是调用我的方法EDT,所以我不浪费时间追逐gremlins。
I always invoke my methods on the EDT so I don't waste time chasing gremlins.
编辑:
说明了线程安全的注释已经从JDK7 API中的许多方法中删除。 http://forums.oracle.com/forums/thread.jspa?threadID=2167051 。这看起来像另一个原因,确保影响GUI的所有方法都在EDT上执行。
I just read another posting which states that the comment "thread safe" has been removed from many methods in the JDK7 API. http://forums.oracle.com/forums/thread.jspa?threadID=2167051. This looks like another reason to make sure all methods that affect the GUI are executed on the EDT.