I have a SwingWorker
that communicates with the server in the background and then updates the JFrame
. I debugged my application and noticed that even after the SwingWorker
its thread still remained. It hangs on Unsafe.park(java.lang.Object)
, which is a native method. I looked further into this and found that all my other SwingWorker
in my application do the same after completion. I can provide the source code if someone wants it, but I donβt think it is necessary, because the problem seems very general.
Update
I started the application without a debugger and the problem is still happening. This is a SwingWorker
thread SwingWorker
:
"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 <0x22ec63d8> (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)
I made an example program that uses SwingWorker
way it is commonly used in an application. This program has the same problem. Here is the 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<Object, String>() { @Override protected Object doInBackground() throws Exception { publish("Background task."); return null; } @Override protected void process(List<String> chunks) { for (String str : chunks) { outputArea.append(str + "\n"); } } @Override protected void done() { outputArea.append("Background task finished."); } }).execute(); } }
source share