The Swing API is single-threaded: you are only allowed to invoke methods on Swing components from the swing thread.
You can have multiple threads in your application, but the moment that another thread needs to interact with the swing components, it needs to do so using EventQueue.invokeLater
. This ensures that the Runnable
is run on the correct thread.
Starting your own Thread
does not have this effect (of running on the Swing thread), so it is not an alternative. If you do it, it may result in data corruption, incorrect screen updates, etc. It may be temporary but it may also be irreparable.
But the invokeLater
method is not an alternative to running your own thread or using a thread pool either since all Runnables
passed to it are executed in sequence, not in parallel.