I have a SwingWorker
class whose doInBackground
executes queries on a remote database. I invoke publish(true)
which sets setVisible
to true for the JDialog holding a loader animation.
Everything is working fine as expected:
- Background method starts.
- JDialog modal is shown.
- Background method completes.
- JDialog is hidden/disposed in
done()
method. - UI is updated with database values.
However, when I point my application to the database running on my local machine the JDialog is shown but never closed/disposed even though the done()
was called. This halts execution of UI code in the done method as well not until I manually close the loader dialog.
This odd behaviour is as follows:
- Background method starts.
- JDialog modal is shown.
- Background method completes.
- JDialog is NOT hidden/disposed in
done()
method. - UI is NOT updated
I must mention that execution over the remote database takes 10 seconds or more but a split second on my local database. How is the faster speed causing this odd behaviour?
Below is my code snippet:
new SwingWorker<Void, Boolean>() {
JDialog loader = new MyDialogLoader();
@Override
protected Void doInBackground() {
publish(true);
//DATABASE EXECUTION CODE IS HERE
publish(false);
return null;
}
@Override
protected void process(List<Boolean> chunks) {
for (Boolean val : chunks) {
loader.setVisible(val);
}
}
@Override
protected void done() {
loader.dispose();
//UI UPDATE WITH DATABASE VALUES CODE HERE;
}
}.execute();