All GUI related code should only be executed from the EDT
. In Android
development, something like this seems to be enforced kind of so you'll get an exception if you do e.g. make a network call in the main thread. However, for developing Java
desktop application, there is no such thing. It is easy to forget about the EDT
and still executing GUI code in another thread. This can cause weird glitches/bugs because Swing
is not thread-safe. Is there a way to strongly enforce the usage of the EDT
for every GUI code by default similar to how Android
is more strict? I do not want to manually check everything and instead get an exception if the EDT
usage recommendation is violated. I'm using IntelliJ IDEA
.
In terms of Java code, something like the following could be inserted automatically for every Swing library method:
if(!SwingUtilities.isEventDispatchThread())
{
throw new IllegalStateException("EDT property violated");
}
Any way to get this?