title: SwingWorker's done() not being executed
body: <p>The done() method not being executed after doInBackground() is finished.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>public class collectingWorker_USB4Java_Async_Fast extends SwingWorker&lt;Void, Void&gt; {     
  
      collectingWorker_USB4Java_Async_Fast(String name) {
          //initialize
          collectingWorkerDone = false;
      }
  
      @Override
      public Void doInBackground() {    
  
          loop = true;  
  
          while(loop){  
              collectData();                
              try {
                  synchronized(TransferCallbackData) {
                      TransferCallbackData.wait();
                  }
              } catch (InterruptedException ex) {
                  Logger.getLogger(GraphPanel_JChart2D.class.getName()).log(Level.SEVERE, null, ex);
              }       
          }
          System.out.println("Out of the loop of collecting worker, loop: " + loop);
          return null;
      }  
  
  
      @Override
      protected void done() {
          collectingWorkerDone = true;
          System.out.println("Collecting worker DONE"); 
      }
  }   
  </code></pre>
  
  <p>But for some reason it is not executed after the doInBackground() is finished.</p>
  
  <p>I have the worker in a while loop. To finished it I just set a boolean (loop) to false. </p>
  
  <pre><code>public void StartPlotting(){      
      Graphs.createCollectingThread();
      Graphs.collectWorker_usb4java_async_fast.execute();
  }        
  
  public void StopPlotting(){ 
      if (Graphs.collectWorker_usb4java_async_fast != null){
          if (Graphs.collectWorker_usb4java_async_fast.getState() == SwingWorker.StateValue.STARTED){
              Graphs.collectWorker_usb4java_async_fast.loop = false;
          }
          //wait until plotting is done
          synchronized(Graphs.collectWorker_usb4java_async_fast.TransferCallbackData){
              Graphs.collectWorker_usb4java_async_fast.TransferCallbackData.notify();
          }
          while(Graphs.collectWorker_usb4java_async_fast.getState() != SwingWorker.StateValue.DONE){
              synchronized(Graphs.collectWorker_usb4java_async_fast.TransferCallbackData){
                  Graphs.collectWorker_usb4java_async_fast.TransferCallbackData.notify();
              }
          }  
      }
  }  
  
  public void StopPlottingWithCheck(){  
      if (Graphs.collectWorker_usb4java_async_fast != null){
          if (Graphs.collectWorker_usb4java_async_fast.getState() == SwingWorker.StateValue.STARTED){
              Graphs.collectWorker_usb4java_async_fast.loop = false;
          }
          //wait until plotting is done
          synchronized(Graphs.collectWorker_usb4java_async_fast.TransferCallbackData){
              Graphs.collectWorker_usb4java_async_fast.TransferCallbackData.notify();
          }
          while(Graphs.collectWorker_usb4java_async_fast.getState() != SwingWorker.StateValue.DONE){
              synchronized(Graphs.collectWorker_usb4java_async_fast.TransferCallbackData){
                  Graphs.collectWorker_usb4java_async_fast.TransferCallbackData.notify();
              }
          }  
      }
      while(Graphs.collectingWorkerDone != true){
          //wait unil transfers dont receive more data
      }
  }
  </code></pre>
  
  <p>If StopPlotting() is called just like that, I get:</p>
  
  <pre><code>Collecting worker DONE
  </code></pre>
  
  <p>However, if I StopPlottingWithCheck() is called, the code stalls.     </p>
  
  <p>In debug mode, I can see that the done() method is executed as soon as StopPlotting() is finished, this leads me to think that I have an EDT synchronization issue or something similar.</p>
  
  <p>Is there any way to ensure that the done() method is executed right away after doInBackground() is finished?</p>