views:

131

answers:

1

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(...)?

+1  A: 

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?)

Tom Hawtin - tackline
er ... so you're saying yes only use the method when I'm on the event thread?
Tom Martin
I am saying that it would be highly advisable to do so.
Tom Hawtin - tackline