Reputation: 6352
My quest to understand swing and EDT continues once again...
Since EDT is EDT, the one and only, I would now like to know which methods, constructors and any other stuff is something that should be done in EDT. I know the general rule, almost all code that creates or interacts with Swing components must run on the event dispatch thread, but that is very general. It is also said that any non thread-safe swing code should be executed on EDT. But I still can't tell which methods are thread-safe, and which aren't.
My question is, is there a list of commands that will eventually be queued on the EDT? (I say that because you don't have to call repaint() from the EDT, but it will execute on it never the less).
If I knew where (and with that I can estimate when relative to the rest of the code) my methods will execute, I could make much more efficient and understandable code.
Most of my EDT work so far has been stabbing in the dark, thus making faulty code and then, when I couldn't figure it out, usually annoy the hell out of people here.
So is there a list, maybe something in Javadocs that I missed? Maybe some more specific rule (e.g., if methods has an "e" in it's name, it has to be executed on the EDT type of specific)?
Upvotes: 0
Views: 151
Reputation: 109815
there isn't something complicated, strange, nor misterious, EDT is alive untill all events are done,
if all events in EDT are done then SwingUtilities.isEventDispatchThread() returns false, always
notice Mouse and Keys events can generating a new events to EDT(some JComponents reacting to those events internally, notifiers implemented in API firing a new event to EDT, then EDT is alive, for example JButton in container and without Focus firing events from ButtonModel, valid for Java6 and never in Win7 and newer), doesn't matter if is there added XxxListener, have to test without
invokeLater() alive EDT in all cases excluding freeze by using Thread.sleep(int)
Thread.sleep(int) can caused to lost all events during sleep(), or Swing GUI is refreshed only on Mouse_Hover_Over
EDIT
in Java7 is possible to creating SecondaryLoop, but I miss real reason for this interface, because all events still must be done on EDT, multithreading is possible to create in Java1.4 same as in Java7
in Java7 some of Thread-safe methods isn't Thread-safe in compare with Java6 on WinXP for MetalLookAndFeel
Upvotes: 2