Run SwingWorker several times
<p>I want to generate a random number 5 times and repeat that 6 times. Every time a random number is generated, I update the GUI with that number and a progress bar.</p>

<p>In order to do so, I've thought of a SwingWorker that generates the random number on the doInBackground() method, and with the publish() method shows that number on the GUI. I've done this with no problem at all, the problem comes when I try to do that 6 times, because in the done() method I add a blank space on the TextField that I use to show all the numbers</p>

<p>How can I do to run 6 times that SwingWorker, and that it starts after the done() method of the SwingWorker is completed?</p>

<p>Thanks!</p>

<p>Edit: the code snippet </p>

<pre><code>public class SwingWorkerEjemplo extends SwingWorker&lt;Void, Integer&gt; {
private JProgressBar pBar;
private JTextField txtSalida;
private JTextArea txtArea;

public SwingWorkerEjemplo(JProgressBar pBar,JTextField txt, JTextArea txtArea) {
    this.pBar = pBar;
    addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("progress".equals(evt.getPropertyName())){
                pBar.setValue((Integer)evt.getNewValue());
            }
        }
    });

    this.pBar.setVisible(true);
    this.pBar.setStringPainted(true);
    this.pBar.setValue(0);
    setProgress(0);
    this.txtSalida = txt;
    this.txtArea = txtArea;
}

@Override
protected Void doInBackground() throws Exception {
    int num;
    for (int i=0;i&lt;5;i++){
        num = ThreadLocalRandom.current().nextInt(1, 7);
        publish(num);
        setProgress(i+1);
        Thread.sleep(100);
    }
    return null;
}

@Override
protected void done() {
    try {
        txtSalida.setText(txtSalida.getText()+" ");
        Thread.sleep(0);
        txtArea.append("");
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

@Override
protected void process(List&lt;Integer&gt; chunks) {
    Integer valor = chunks.get(chunks.size()-1);
    txtSalida.setText(txtSalida.getText()+String.valueOf(valor));
}
</code></pre>

<p>}</p>

<p>And in the MainWindow.java</p>

<pre><code>SwingWorkerEjemplo swe = new SwingWorkerEjemplo(pBar, txtNumeros, txtSalida);
swe.execute();
System.out.println("Worker 1");
swe = new SwingWorkerEjemplo(pBar, txtNumeros, txtSalida);
swe.execute();
System.out.println("Worker 2");
swe = new SwingWorkerEjemplo(pBar, txtNumeros, txtSalida);
swe.execute();
System.out.println("Worker 3");
swe = new SwingWorkerEjemplo(pBar, txtNumeros, txtSalida);
swe.execute();
System.out.println("Worker 4");
swe = new SwingWorkerEjemplo(pBar, txtNumeros, txtSalida);
swe.execute();
System.out.println("Worker 5");
swe = new SwingWorkerEjemplo(pBar, txtNumeros, txtSalida);
swe.execute();
System.out.println("Worker 6");
</code></pre>

<p>The result is first all the 
Worker 1
Worker 2
Worker 3
Worker 4
Worker 5
Worker 6
and then something like xxxxxyyyyyzzzzzaaaaabbbbbcccccddddd</p>