Do JFrame windows in Swing run on their own separate threads?
<p>I have three questions which are closely related in that they are born out of each other and represent a train of thought, so I am posting them under one question. It would not help me construct the big picture of my question if I posted them separately.</p>

<p>1) Could you please explain in simple language what <code>SwingUtilities.invokeLater</code> does? I understand threading, dare I say quite a bit, but still the language of the documentation confuses me. It says:</p>

<blockquote>
  <p>Causes <i>doRun.run()</i> to be executed asynchronously on the
  AWT event dispatching thread.  This will happen after all
  pending AWT events have been processed.  This method should
  be used when an application thread needs to update the GUI.
  In the following example the <code>invokeLater</code> call queues
  the <code>Runnable</code> object <code>doHelloWorld</code>
  on the event dispatching thread and
  then prints a message.</p>
</blockquote>

<p>If I put some effort in to make sense of what that says, I think here is what it says, but I couldn't be so sure about it. I think it says:</p>

<p><em>The <code>invokeLater</code> method schedules the main window creation and the setting up of its dispatcher / message pump on the primary thread of the application only and not on a separate thread. It does it by <strong>posting</strong> the message to create the window and set it up on the <strong>main / primary application thread</strong>. In other words, the main thread is saying to us, "The window you are asking me to create will be created after I am done doing everything else that is on my plate right now."</em></p>

<p>But then two things confuses me, which I list as the two questions below.</p>

<p>2) Then why do I need to implement the new window's message loop as a <code>Runnable</code>. This implies that I want a separate thread to execute that message loop.</p>

<p>3) I printed out the current thread Id's in the function that creates the window and the function that is the window's message loop, and they are both different threads. So, each window in Swing runs on its own thread? That is insane. Can you please explain to me what is happening here? And also if you could please explain in a paragraph or two the threading model of GUI applications created in Swing?</p>

<pre><code>public static void main(String[] args) {
        SwingUtilities.invokeLater(new MainWindowEventLoop());
        System.out.println(String.format("Main thread %1$d started.",
                            Thread.currentThread().getId()));
    }

public class MainWindowEventLoop implements Runnable {

    @Override
    public void run() {
        JFrame mainWindow = new MainWindow("Main Window");
        System.out.println(String.format("Main window loop running on thread %1$d.", 
                            Thread.currentThread().getId()));
    }
}
</code></pre>

<blockquote>
  <p><strong>Output:</strong></p>
  
  <p>Main thread 1 started.</p>
  
  <p>Main window loop running on thread 14.</p>
</blockquote>