title: Kafka Consumer poll() returns empty set when used inside while loop
body: <p>I have a basic implementation of a Kafka Consumer. I have it working properly when it is calling the <strong><code>poll()</code></strong> method on button click (let's call this <strong>V1</strong>). </p>
  
  <p>But as soon as I place the <strong><code>poll()</code></strong> method inside a <strong><code>while</code></strong> loop (let's call this <strong>V2</strong>), I stop receiving the messages. </p>
  
  <p>The weird thing is that <strong>V1</strong> is still able to pick up the new messages but <strong>V2</strong> still receives an empty <code>ConsumerRecords</code> object.</p>
  
  <p>I have made sure that <strong>V1</strong> and <strong>V2</strong> are in different <strong><code>ConsumerGroups</code></strong>.</p>
  
  <p>Here, <strong>V2</strong> contains the code as shown below.</p>
  
  <p>And <strong>V1</strong> has the <strong><code>while</code></strong> loop removed. Otherwise there is <strong>no</strong> other point of difference.</p>
  
  <p><strong>Can someone tell me what is happening and why?</strong></p>
  
  <p><strong>Code Reproduced below:</strong></p>
  
  <pre><code>btnButton.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent arg0){
           while(true) {
               ConsumerRecords&lt;String, String&gt; records = consumerGroupObj.consumerObj.poll(100);
  
               // Trying to insert into DefaultTableModel here for an existing jTable
  
               // Some other processing code
           }
      }
  }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>I noticed something here. It might not be the <strong><code>poll()</code></strong> method that is causing this. But the enclosing <strong>eventHandler</strong>. Please check the code provided above for updates.</p>
  
  <p>What I've noticed is that, until the control exits this <strong><code>mouseClicked()</code></strong> method, the changes made by the code inside are not visible in the GUI.</p>
  
  <p>So, my new question: <strong>How do I make a Kafka consumer run in an infinite loop that is started by a button click event?</strong></p>