Standard scenario: User presses button and starts big task. EventThread creates SwingWorker
to execute the task and get's on with life.
Now, since the big task is highly parallelizable, the first thing the SwingWorker
thread does is to create a bunch of worker threads and farms the work out.
My question: Are the worker threads allowed to call SwingWorker#publish()
to trigger a GUI
update or is only the SwingWorker
thread allowed to do so?
Thanks, Carsten
[Edit] Some pseudo code to make my use-case a bit clearer. The quesiton is basically: Is the code below OK? And what if I leave out waitForAllWorkerThreadsToFinish();
?
public class MySwingWorker extends SwingWorker {
class MyWorkerThread extends Runnable {
void run() {
while(!exitCondition) {
doSomeWork();
publish(progressUpdate);
reEvaluateExitCondition();
}
}
}
public Void doInBackground() {
createAndStartBunchOfMyWorkerThreads();
waitForAllWorkerThreadsToFinish();
}
void process(List<V> chunks) {
updateGuiWithProgress(chunks);
}
}