title: Runnable won't stop when using a BlockingQueue
body: <p>I have a Runnable that won't stop even though the conditions are set to stop. Not sure why it's happening. Sometimes a few Threads are still alive other are not. I've left it run for over an hour to see if it would stop but it doesn't. Does it have something with the way I'm passing arguments?</p>
  
  <pre><code>public class ParserWorker implements Runnable {
  
      private BlockingQueue&lt;String&gt; queue = null;
      private ZipReader zip = null;
  
      public ParserWorker(BlockingQueue&lt;String&gt; queue, ZipReader zip) {
          this.queue = queue;
          this.zip = zip;
      }
  
      @Override
      public void run() {
          try {
              while (!queue.isEmpty() || !zip.isClosed()) {
                  String line = queue.take();
              }
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>This is the class that starts everything. </p>
  
  <pre><code>public Start() throws InterruptedException   {
      File zipFile = new File("C:\\development\\data2.zip");
      BlockingQueue&lt;String&gt; queue = new ArrayBlockingQueue&lt;String&gt;(1024);
  
      ZipReader zip = new ZipReader(queue, zipFile);
  
      ParserWorker w1 = new ParserWorker(queue, zip);
      ParserWorker w2 = new ParserWorker(queue, zip);
      ParserWorker w3 = new ParserWorker(queue, zip);
      ParserWorker w4 = new ParserWorker(queue, zip);
  
      //Start reading zip file
      Thread zipThread = new Thread(zip);
      zipThread.start();
  
      //Give a little pause to allow the queue to fill
      Thread.sleep(1000);
  
      //Starts the Consumable Threads
      Thread t1 = new Thread(w1);
      Thread t2 = new Thread(w2);
      Thread t3 = new Thread(w3);
      Thread t4 = new Thread(w4);
  
      t1.start();
      t2.start();
      t3.start();
      t4.start();
  
      //waits until the zip file is closed.
      while (!zip.isClosed()) {
          Thread.sleep(5000);
      }
  
      //By this point the Zip file is closed, queue may still contain items
      System.out.println("Queue isEmpty:" + queue.isEmpty() + ", Zip isClosed:" + zip.isClosed());
  
      //Waits until the Queue is empty
      while (!queue.isEmpty()) {
          Thread.sleep(5000);
      }
  
      //By this point the Zip file is closed and the queue is empty.
      System.out.println("Queue isEmpty:" + queue.isEmpty() + ", Zip isClosed:" + zip.isClosed());
  
      while (t1.isAlive() || t2.isAlive() || t3.isAlive() || t4.isAlive()) {
          System.out.println("T1 alive:" + t1.isAlive() + ", T2 alive:" + t2.isAlive() + ",T3 alive:" + t3.isAlive() + ",T4 alive:" + t4.isAlive());
          Thread.sleep(5000);
      }
  
  
      System.out.println("Done");
  </code></pre>
  
  <p>I've included the ZipReader for clarification.</p>
  
  <pre><code>public class ZipReader implements Runnable{
  
      private boolean closed = true;
      private File zipFileName = null;
  
      protected BlockingQueue&lt;String&gt; queue = null;
  
      public ZipReader(BlockingQueue&lt;String&gt; queue, File zipFileName) {
          this.queue = queue; 
          this.zipFileName = zipFileName;
      }
  
      public boolean isClosed() {
          return closed;
      }
  
      @Override
      public void run() {
        String line = null;
        long index = 1L;
        ZipFile zipFile = null;
  
        try {
              System.out.println("Opening Zip file");
              zipFile = new ZipFile(zipFileName);
              closed = false;
              System.out.println("Getting entries");
              Enumeration&lt;? extends ZipEntry&gt; entries = zipFile.entries();
              while (entries.hasMoreElements()) {
                  ZipEntry zipEntryObj = entries.nextElement();
                  System.out.println("Processing file: " + zipEntryObj.getName());
                  InputStream input = zipFile.getInputStream(zipEntryObj);
                  InputStreamReader isr = new InputStreamReader(input);
  
                  BufferedReader br = new BufferedReader(isr);
                  while ((line = br.readLine()) != null) {
  //                    if (index++ % 10000 == 0) {
  //                        System.out.println("Index:" + index);
  //                    }
  //                    System.out.println(line);
                      queue.put(line);
                  }
                  br.close();
                  System.out.println();
              }
          } catch (IOException e) {
              e.printStackTrace();
          } catch (InterruptedException e) {
              e.printStackTrace();
          } finally {
              System.out.println("Closing zip file");
              try {
                  if (zipFile != null) {
                      zipFile.close();
                  }
                  closed = true;
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
          }
      }
  
  }
  </code></pre>
  
  <p>Here is the output I get. </p>
  
  <pre><code>Opening Zip file
  Getting entries
  Processing file: data01.txt
  Processing file: data02.txt
  Processing file: data03.txt
  Processing file: data04.txt
  Processing file: data05.txt
  Processing file: data06.txt
  Processing file: data07.txt
  Processing file: data08.txt
  Processing file: data09.txt
  Processing file: data10.txt
  Closing zip file
  Queue isEmpty:true, Zip isClosed:true
  Queue isEmpty:true, Zip isClosed:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  T1 alive:true, T2 alive:true,T3 alive:true,T4 alive:true
  </code></pre>