2
I have a method that performs two tasks. I would like two threads
perform each task. Tasks do not share data, are completely independent.
Before starting the tasks is shown a dialog
with the information "Wait, processing...".
Here are the codes:
final JDialog dialog = new JDialog(this, true);
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Faz trabalho
return null;
}
@Override
protected void done() {
// Devo fechar Dialog? O outro terminou?
}
};
SwingWorker<Void, Void> worker2 = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Faz trabalho
return null;
}
@Override
protected void done() {
//Devo fechar Dialog? O outro terminou?
}
};
worker.execute();
worker2.execute();
dialog.setVisible(true);
// Devo fechar o dialog aqui?
The questions are already commented on in the code.
I would like to close the dialog
only when both threads
finished. How to know when they finished? Who should close the dialog
?
That’s easy, that’s when a third thread comes into play! /s
– Bacco