title: Infinite loop in runnable goes out?
body: <p>Some simplified code to illustrate my problem:</p>
  
  <pre><code>public class QueriesQueueRunnable implements Runnable {
  
      private List&lt;String&gt; queue = new ArrayList&lt;String&gt;();
  
  
      @Override
      public void run() {
          while(true){
              if (!this.getQueue().isEmpty()) {
                      System.out.println(this.getQueue().get(0));
                      this.getQueue().remove(0);
  
              }
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>QueriesQueueRunnable queriesQueueRunnable = new QueriesQueueRunnable();
  Thread thread = new Thread(queriesQueueRunnable).start();
  
  
  
  
  for (int i = 0; i &lt; 1000; i++) {
       if(i==500){
           try {
                  Thread.sleep(5000);                 
              } catch(InterruptedException ex) {
                  Thread.currentThread().interrupt();
              }
       }
      queriesQueueRunnable.getQueue().add(String.valueOf(i));
  }
  </code></pre>
  
  <p>The output is only showing until the i==499 iteration. Why? It's like the execution goes out of the runnable loop.</p>
  
  <p>Java 1.7</p>