Component.getGraphicsConfiguration 线程安全吗?
如果您不在 AWT 事件线程中,则不应调用许多方法。 这些通常是以某种方式操纵 UI 的方法。
Component 的 getGraphicsConfiguration(...) 也是这种情况吗? 它只是一个 getter,但如果事件线程正在等待调用此方法的线程,它似乎会导致死锁。
虽然解决死锁相当简单(避免在事件线程上使用等待或同步),但我是否应该只在传递给 SwingUtilities.invokeLater(...) 或 invokeAndWait(...) 的 Runnable 中调用 getGraphicsConfiguration ?
There are many methods you shouldn't call if you are not on the AWT event thread. These are generally methods that manipulate the UI in some way.
Is this the case with Component's getGraphicsConfiguration(...)? It is only a getter but it appears to cause a deadlock if the event thread is waiting on the thread calling this method.
Whilst solving the deadlock is fairly trivial (avoid using wait or synchronize on the event thread), should I only be calling getGraphicsConfiguration in a Runnable passed to SwingUtilities.invokeLater(...) or invokeAndWait(...)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AWT 线程安全性(必然)被破坏。 只是不要靠近它。 保持直接的 AWT EDT
另请注意,仅仅因为方法位于 java.awt.Component 中,并不意味着该对象(或其引用的对象)不在 Swing 中,因此实际上甚至根本不假装是线程安全的。 (还不够吗?)
AWT thread-safety is (necessarily) broken. Just don't go anywhere near it. Stay on the straight AWT EDT
Also note that just because a method is in
java.awt.Component
, it does not mean that the object (or an object referenced by it) is not in Swing and therefore really not even pretending to be thread-safe at all. (Enough nots?)