Why should SwingUtils.invokeAndWait() method be called outside an EDT thread?

  private void init() 
    JFrame jfr = new JFrame();
    jfr.setSize(500, 500);

    JButton jb = new JButton("Ok");

    jb.addActionListener(new ActionListener()
        public void actionPerformed(ActionEvent e)
                SwingUtilities.invokeAndWait(new Runnable() 
                    public void run() 
            catch (Exception e1) 

First Question :(While using InvokeAndWait)

Why is it implemented in such a way that it throws an InvocationTargetException when called within EDT Thread?

Second Question:(while using InvokeLater)

Why InvokeLater allows this ?

Well, this is my basic understanding on EDT threads:


  • Places job F into the EDT event queue and waits until the EDT has
    executed it.
  • This call blocks until all pending AWT events(A, B, C, D, E) have
    been processed and (then) execute F after which the control
  • Returns if and only if the job submitted is completed.(Control
    returns after F is completed.)
  • Technically, a Synchronous blocking call.


  • Places the job F into the EDT Queue , but doesn’t wait for its
    completion.(Basically , a publish and return call).
  • If we don’t care about the job completion we can use InvokeLater.
  • Technically, a Asynchronous non-blocking call.

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.