Java EventQueue. Why should everything be in invokelater method? Java EventQueue. Why should everything be in invokelater method? multithreading multithreading

Java EventQueue. Why should everything be in invokelater method?


The main thread isn't the same as the EDT. If you add System.out.println(Thread.currentThread().getName() you'll see it print out main within main() and AWT-EventQueue-0 when within the run() method of the Runnable.

Here is a discussion of the history of the single threaded rule in Swing that might help make things clearer.


Desktop GUI applications usually work in this way. There is one thread for gui and one or several threads for rest of application. Using EventQueue you specify what GUI thread should do from other threads.