title: Processing all elements in a BlockingQueue
body: <p>I am parsing an XML document, building an object from the information that I parse, and then putting that object into a blocking queue.</p>
  
  <p>For testing purposes, the size of the blocking queue is 3 and I have 4 pages that I need to process.  What I'd like to happen is that after all possible objects have been added they should all be taken off.  I've tried using a while loop (as shown below) to take all the elements out of the queue but a there seems to be a null preventing it from going through the rest of the queue.</p>
  
  <p>I'm new to threads in Java and I'm guessing that's where my trouble lies.</p>
  
  <p>Any help would be appreciated.</p>
  
  <pre><code>Runnable parser = new Runnable()
  {
      public void run()
      {
          try
          {
              saxParser.parse("file_to_parse.xml", handler);
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
      }
  };
  
  Runnable takeOff = new Runnable()
  {
      public void run()
      {
          try
          {
              while(handler.bq.peek() != null)
              {
                  handler.bq.take();
              }
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
      }
  };
  
  new Thread(parser).start();
  new Thread(takeOff).start();
  </code></pre>