<p>It is normally used to create stream with mapper function like <code>itemList.stream().map(item -&gt; someFunction(item)).toList()</code>. However, if <code>itemList</code> is too large in size and <code>someFunction</code> is time consuming, e.g. calling API or I/O, it will generate spike in memory usage and thus get killed by kubernetes controller.</p>
<p>Is there a way to thorttle the stream mapper function invocation? Or just execute it in a sequential way with for-loop?</p>

Mike
<p>The Java 8 streams are in fact like a different syntax for loops and iterations, so they run synchronous and immediately.</p>
<p>You can either implement you logic in a different way to ensure a fixed amount of memory usage, or if time based throttling would indeed help you can look into reactive programming libraries like spring reactor or rxjava. They offer asynchronous data streams.</p>
