title: (Kafka) Streams - foreach inside foreach
body: <p>I have a piece of code that iterates over a KStream and checks if a condition is met. When it is the case, it calls another method to do some other processing. The code looks like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>stream1.foreach((k, v) -&gt; {
          if (someCondition) {
              System.out.println("Triggered Join");
              joinStreams();
          }
      }
  });
  </code></pre>
  
  <p>Now, the body of <code>joinStreams()</code> method looks like the following (just for testing purposes).</p>
  
  <pre class="lang-java prettyprint-override"><code>private static void joinStreams() {
      System.out.println("Started Join");
      stream2.foreach((k, v) -&gt; System.out.println("OK"));
  }
  </code></pre>
  
  <p>When <code>joinStreams()</code> is called, it only prints "Started Join" and hangs for ever. When I call it straightforward from <code>main()</code>, it prints "Started Join" followed by as many "OK" as there are messages in the stream (which is its normal behavior).
  My question is: what might cause this weird result ? 
  P.S: As I did understand, the problem is with the foreach (from <code>joinStreams()</code>) inside a foreach (of <code>stream1</code>).</p>