title: Calling a method from ActionPerformed and running it on main thread
body: <p>my program's UI freezes for some time after pressing a JButton. I discovered that a cause of this is a Semaphore clogging the Swing thread. This is the method containing the <code>acquire()</code> call on the Semaphore:  </p>
  
  <pre><code>  private void fetch(int numThreads) {
      //some code here
      sem = new Semaphore(numThreads);
      for (int i = 0; i &lt; model.getRowCount(); i++){
        try {
          sem.acquire();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
       //some code here
      }
  </code></pre>
  
  <p>And here is the only method that makes a call to <code>fetch()</code></p>
  
  <pre><code>concFetchButt.addActionListener(new ActionListener() {
  
    @Override
    public void actionPerformed(ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
  
        @Override
        public void run() {
          switchButtonStates(false);
        }
  
      });
  
      fetch(Integer.parseInt(threadsNumField.getText()));
    }
  </code></pre>
  
  <p>As I understand, this code ends up running <code>fetch()</code> on the Swing thread, though, supposedly it has nothing to do with Swing. </p>
  
  <p>I guess, my question is this: How do I run a method called from 'ActionPerformed()' of Swing on the main thread of the program instead of the Swing thread?</p>