SwingWorker.execute() does nothing
- From: Ben Phillips <b.phillips@xxxxxxxxxxxxxxxxx>
- Date: Wed, 08 Oct 2008 02:45:22 -0400
I've got a strange app hang. A particular button click pops up a modal "Please Wait" dialog, then constructs a SwingWorker implementation and calls execute() on it. The done() method removes the dialog.
Nothing happens as a result of execute(), and as a result the dialog never goes away and the app is hung.
This is a really strange one, because nothing in the API docs or tutorial gives any hint as to what the problem could be.
My done() method calls get(), so I thought it could be hanging there (though it really shouldn't, since done() shouldn't be called until it's, well, done).
But I put a debugging System.out.println() in doInBackground() and it never printed its message.
The worker being executed is definitely of the same class as contains my overridden doInBackground() and done() methods.
doInBackground() has the println as its first thing.
done() hides that dialog before calling get() so even if somehow only done() was getting called, and get() hanging as a result, the modal dialog should have disappeared. It didn't.
In short, neither doInBackground() nor done() is being called.
Both of my implementations have @Override tags and there are no compiler errors, so it's not the case that I'm accidentally failing to override and it's actually running do-nothing superclass implementations of those methods.
The SwingWorker subclass instance is a fresh one. The code is FooWorker worker = new FooWorker(argument); worker.execute();
Put simply, SwingWorker.execute() appears to be doing nothing.
What could the problem be?
The javadocs for execute() say:
Schedules this SwingWorker for execution on a worker thread. There
are a number of worker threads available. In the event all worker
threads are busy handling other SwingWorkers this SwingWorker is
placed in a waiting queue.
It seems to be a bug is the sole SwingWorker can get put on a waiting queue and never run. Or is an app that uses SwingWorker supposed to do something to set the size of the thread pool larger than zero before any of this stuff will work correctly?
On a side note, JFrame.setLocationRelativeTo(null) is supposed to center the frame; it seems to center the upper left corner. Is there an easy way to center the frame? JDialog.setLocationRelativeTo(theDialogOwner) also doesn't seem to center appropriately.
.
- Follow-Ups:
- Re: SwingWorker.execute() does nothing
- From: Roedy Green
- Re: SwingWorker.execute() does nothing
- From: Thomas Kellerer
- Re: SwingWorker.execute() does nothing
- From: Stefan Rybacki
- Re: SwingWorker.execute() does nothing
- From: Mark Space
- Re: SwingWorker.execute() does nothing
- Prev by Date: Re: Using a method to return a value, that uses a modal dialog
- Next by Date: Re: fetch content from google results
- Previous by thread: JComboBox: setting the editable text
- Next by thread: Re: SwingWorker.execute() does nothing
- Index(es):