title: Use swingWorker with other classes
body: <p>I'm starting to work with Java GUIs and I have some problems with SwingWorker: I'm trying to do a simple UI to start a server, run some "slave" objects and finally, run a master object managing all the work. I define the problem in the master (the number of tasks to do) and I have a progressBar in the UI that I want to update each time a task is done. I use a SwingWorker to update the progressBar, but I don't know how to do it right: in the background method it just sleeps until the master wakes it up when a task is done. Unfortunately it doesn't work and I would appreciate if someone could explain me what should I do.</p>
  
  <p>I create the swingworker in the GUI and add a listener for update a progressBar:</p>
  
  <pre><code>private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
  
          worker = WorkerUpdater.getInstance();
          jProgressBar1.setValue(0);
          worker.addPropertyChangeListener(this);
          worker.execute();
  </code></pre>
  
  <p>This is the SwingWorker:</p>
  
  <pre><code>public class WorkerUpdater extends SwingWorker&lt;Void, Integer&gt; {
  
      private static WorkerUpdater instance;
      private int progress;
      private boolean changed = false;
  
      public int getProgreso(){
          return this.progress;
      }
  
      public void setProgreso(int p){
          this.progress = p;
          changed = true;
      }
  
      public static WorkerUpdater getInstance(){
          if(instance == null)
              instance = new WorkerUpdater();
          return instance;
      }
  
      @Override
      protected Void doInBackground() throws Exception {
          while(progress &lt; 100){
              if(changed){
                  setProgress(Math.min(progress, 100));
                  changed = false;
              }
          }
          return null;
      }
  
  }
  </code></pre>
  
  <p>And I want to update the value of the progress bar when a task is done in other class (client):</p>
  
  <pre><code>    public boolean taskIsDone(String taskID, Object[] retVal) throws RemoteException {
  
          System.out.println("Client: taskIsDone(): Old task: " + taskID);
  
          this.doneTasks++;
          this.progress = ((Double) Math.ceil(doneTasks / totalTasks)).intValue();
  
          synchronized (taskSynch) {
              worker.setProgress(progress);
              this.results.put(taskID, retVal);
              task_count--;
              taskSynch.notify();
          }
  
          System.out.println("Client: Task finished: " + taskID);
  
          return true;
      }
  </code></pre>
  
  <p>The problem is that the value of progress in the client class changes its value but the progress bar doesn't.</p>