Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new Thread created when calling SwingUtilities.invokeAndWait()?

Is a new Thread created when Runnable is used with SwingUtilities.invokeAndWait()?

like image 681
program-o-steve Avatar asked May 09 '11 13:05

program-o-steve


People also ask

Can invokeAndWait be called from the event dispatching thread?

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.

What does invokeAndWait() do in swing?

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.

Is there a multi-threaded GUI in swing?

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.

What is the Event Dispatch Thread in swing?

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.


2 Answers

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.

like image 148
Suhail Gupta Avatar answered Oct 17 '22 01:10

Suhail Gupta


invokeAndWait API.

Causes doRun.run() to be executed synchronously on the AWT event dispatching thread

like image 22
Grammin Avatar answered Oct 16 '22 23:10

Grammin