Is a new Thread created when Runnable is used with SwingUtilities.invokeAndWait()
?
It shouldn't be called from the event dispatching thread. Here's an example that creates a new application thread that uses invokeAndWait to print a string from the event dispatching thread and then, when that's finished, print a string from the application thread.
To understand what invokeAndWait () does, you first need to understand the event/thread model of Swing. Basically, everything that affects the GUI in any way must happen on a single thread. This is because experience shows that a multi-threaded GUI is impossible to get right.
This is because experience shows that a multi-threaded GUI is impossible to get right. In Swing, this special GUI thread is called the Event Dispatch Thread, or EDT. It is started as soon as a Swing top-level component is displayed, and it's bascially a worker thread that has a FIFO queue of event objects that it executes one after another.
In Swing, this special GUI thread is called the Event Dispatch Thread, or EDT. It is started as soon as a Swing top-level component is displayed, and it's bascially a worker thread that has a FIFO queue of event objects that it executes one after another. When a Swing GUI needs to be drawn or updated, the JRE places an event on the EDT queue.
No,a new thread is not created when Runnable is used with SwingUtilities.invokeAndWait()
.
The Event Thread will end up calling the run() method of the Runnable when it's turn comes up on
the event queue.
invokeAndWait API.
Causes doRun.run() to be executed synchronously on the AWT event dispatching thread
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With