title: SwingWorker hangs at Unsafe.park()
body: <p>I have a <code>SwingWorker</code> that communicates with a server in the background and then updates a <code>JFrame</code>. I was debugging my app and noticed that even after the <code>SwingWorker</code> finished its work, its thread still remained. It is hanging at <code>Unsafe.park(java.lang.Object)</code> which is a native method. I looked in to this further and found that all my other <code>SwingWorker</code>s in my app do the same thing after they finish. I can provide source code if someone wants it but I don't think it is necessary because the problem seems to be very general.</p>
  
  <h3>Update</h3>
  
  <p>I ran the app without the debugger and the problem is still happening. This is the dump of the <code>SwingWorker</code> thread:</p>
  
  <pre><code>"SwingWorker-pool-2-thread-1" daemon prio=6 tid=0x03219800 nid=0xd74 waiting on
  condition [0x04b7f000]
     java.lang.Thread.State: WAITING (parking)
          at sun.misc.Unsafe.park(Native Method)
          - parking to wait for  &lt;0x22ec63d8&gt; (a java.util.concurrent.locks.Abstra
  ctQueuedSynchronizer$ConditionObject)
          at java.util.concurrent.locks.LockSupport.park(Unknown Source)
          at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject
  .await(Unknown Source)
          at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
          at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I made a sample program that uses <code>SwingWorker</code> the way it is normally used in a application. This program has the same problem. Here is the code:</p>
  
  <pre><code>package swingworkerlocktest;
  
  import java.util.List;
  import javax.swing.JFrame;
  import javax.swing.JTextArea;
  import javax.swing.SwingWorker;
  
  public class SwingWorkerLockTest {
  
      public static void main(String[] args) {
          final JFrame frame = new JFrame("Frame");
          final JTextArea outputArea = new JTextArea(4, 20);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(outputArea);
          frame.pack();
          frame.setVisible(true);
          (new SwingWorker&lt;Object, String&gt;() {
              @Override
              protected Object doInBackground() throws Exception {
                  publish("Background task.");
                  return null;
              }
  
              @Override
              protected void process(List&lt;String&gt; chunks) {
                  for (String str : chunks) {
                      outputArea.append(str + "\n");
                  }
              }
  
              @Override
              protected void done() {
                  outputArea.append("Background task finished.");
              }
          }).execute();
      }
  }
  </code></pre>