Why does parallel stream with lambda in static initializer cause a deadlock?
<p>I came across a strange situation where using a parallel stream with a lambda in a static initializer takes seemingly forever with no CPU utilization. Here's the code:</p>

<pre><code>class Deadlock {
    static {
        IntStream.range(0, 10000).parallel().map(i -&gt; i).count();
        System.out.println("done");
    }
    public static void main(final String[] args) {}
}
</code></pre>

<p>This appears to be a minimum reproducing test case for this behavior. If I:</p>

<ul>
<li>put the block in the main method instead of a static initializer,</li>
<li>remove parallelization, or</li>
<li>remove the lambda,</li>
</ul>

<p>the code instantly completes. Can anyone explain this behavior? Is it a bug or is this intended?</p>

<p>I am using OpenJDK version 1.8.0_66-internal.</p>