title: While loop with threads does not stop
body: <p>I am using a while loop to know when to stop the application and I'm using an executor service for threads:</p>
  
  <pre><code>ExecutorService executorService = Executors.newFixedThreadPool(8);
  String[] error = {""};
  while(!(error[0].equals("Nothing found"))) {
      executorService.execute(new Runnable() {
          @Override
          public void run() {
              addProductsToSet();
  
              //rest of the code
              synchronized (error[0]) {
                  error[0] = // code that might return "Nothing found" to stop the while loop
              }
              //rest of the code
          } //end of run method
      });
  }
  
  executorService.shutdown();
  while(!executorService.isTerminated()) {
  }
  </code></pre>
  
  <p>The problem that I have is that <code>error[0]</code> has the value "Nothing found" but the code just doesn't stop. It goes and goes on forever. If I'm not using threads, the while loop stops. I also tried <code>executorService.shutdownNow()</code> but doesn't work. </p>
  
  <p>Any suggestions?</p>