Skip to main content

SwingWorker : deadlock ?

1 reply [Last post]
laps
Offline
Joined: 2005-12-09
Points: 0

Hi,
I'm using jre 1.6.0_21.
In some cases, when I use a SwingWorker thread, it remains alive once the work is done. Here is an example :

Quote:

new SwingWorker<Boolean, Boolean>() {
@Override
protected Boolean doInBackground() throws Exception {
try {
Thread.currentThread().setName("SWorker");
} catch (Throwable t) {
return false;
}
return true;
}
@Override
public void done() {
try {
if (get()) {
}
} catch (Throwable t) {

} finally {
super.done();
}
}
}.execute();

The block in the if statement is correctly executed. No exception is thrown at all, but, a Thread dump shows the SWorker thread as this :

Quote:

Daemon Thread [SWorker] (Suspended)
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.park(Object) line: 158
AbstractQueuedSynchronizer$ConditionObject.await() line: 1987
LinkedBlockingQueue<E>.take() line: 399
ThreadPoolExecutor.getTask() line: 947
ThreadPoolExecutor$Worker.run() line: 907
Thread.run() line: 619

The problem is I call my Swingworker when I open a new frame, and the content of this frame is totally empty. However, the EDT thread stack seems to be correct (EventQueue.wait).
I ran jConsole to get more information about the SWorker thread, and here is the raised information :
Quote:

Name: SWorker
State: WAITING on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@d7338e
Total blocked: 338 Total waited: 339

Stack trace:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987)
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
java.lang.Thread.run(Thread.java:619)

Here is another suspicious thread :

Quote:

RMI Scheduler :
Name: RMI Scheduler(0)
State: TIMED_WAITING on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@1194cf5
Total blocked: 0 Total waited: 8

Stack trace:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:198)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2025)
java.util.concurrent.DelayQueue.take(DelayQueue.java:164)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:583)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:576)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
java.lang.Thread.run(Thread.java:619)

Could it be a JDK issue ?
Thanks for help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
laps
Offline
Joined: 2005-12-09
Points: 0

Sorry I posted a bit fast :
In fact, the SwingWorker thread seems to have a normal behaviour. I don't know if the fact I call it from the addNotify() method has a relationship with the fact that my panel remains empty and does not layout, but this bug is not easily reproductible...