<story><title>Java 8 Features</title><url>http://www.infoq.com/articles/Java-8-Quiet-Features?utm_source=hackernews&amp;utm_medium=link&amp;utm_campaign=8java_article</url><text>If you haven’t seen some of the videos or tutorials around Java 8, you’ve probably been super-busy or have a more interesting social life than I do (which isn’t saying much). With new features like lambda expressions and Project Nashorn taking so much of the spotlight, I wanted to focus on some new APIs that have been a bit under the radar, but make Java 8 better in so many ways.</text></story><parent_chain><item><author>goblue96</author><text>I can&amp;#x27;t wait to do code reviews where people are sprinkling parallelSort() all over the place, not understanding the consequences.&lt;p&gt;Serious question: isn&amp;#x27;t this something the JVM could abstract away?</text></item></parent_chain><comment><author>bhauer</author><text>Good point.  There is definitely a challenge of knowing when a single-threaded collection or stream operation may be preferable to the parallel option.  When my colleague wrote his summary of Java 8 [1], he wrote:&lt;p&gt;&lt;i&gt;Returning to the concept of parallel streams, it&amp;#x27;s important to note that parallelism is not free. It&amp;#x27;s not free from a performance standpoint, and you can&amp;#x27;t simply swap out a sequential stream for a parallel one and expect the results to be identical without further thought. There are properties to consider about your stream, its operations, and the destination for its data before you can (or should) parallelize a stream. For instance: Does encounter order matter to me? Are my functions stateless? Is my stream large enough and are my operations complex enough to make parallelism worthwhile?&lt;/i&gt;&lt;p&gt;The author of the linked InfoQ article (OP) cites that same dilemma by explaining the potential for context-switching overhead to counter the advantage of splitting the work.&lt;p&gt;Abstracting it away with rough heuristics might be possible, but doing so with consistent success could be challenging.  In other words, you could elect to use the serial algorithm for small collections, or when the CPU contention at the start of the sort operation is low.  But if the comparison operator is expensive, CPU contention is volatile, or if operating on a stream of unknown length, the abstraction may choose poorly.  Ultimately, I like the option to choose for myself, but like you, I wouldn&amp;#x27;t mind having a third option that defers that choice to some heuristic.&lt;p&gt;[1] &lt;a href=&quot;http://www.techempower.com/blog/2013/03/26/everything-about-java-8/&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.techempower.com&amp;#x2F;blog&amp;#x2F;2013&amp;#x2F;03&amp;#x2F;26&amp;#x2F;everything-about-...&lt;/a&gt;</text></comment>
<story><title>Java 8 Features</title><url>http://www.infoq.com/articles/Java-8-Quiet-Features?utm_source=hackernews&amp;utm_medium=link&amp;utm_campaign=8java_article</url><text>If you haven’t seen some of the videos or tutorials around Java 8, you’ve probably been super-busy or have a more interesting social life than I do (which isn’t saying much). With new features like lambda expressions and Project Nashorn taking so much of the spotlight, I wanted to focus on some new APIs that have been a bit under the radar, but make Java 8 better in so many ways.</text></story><parent_chain><item><author>goblue96</author><text>I can&amp;#x27;t wait to do code reviews where people are sprinkling parallelSort() all over the place, not understanding the consequences.&lt;p&gt;Serious question: isn&amp;#x27;t this something the JVM could abstract away?</text></item></parent_chain><comment><author>blt</author><text>Reminds me of a funny comment on Stack Overflow:&lt;p&gt;&amp;gt; &lt;i&gt;This continual creation&amp;#x2F;termination&amp;#x2F;destruction of threads is done so often that I wonder where the idea came from. I presume some poisonous textbook is responsible. Sometimes, it seems that the whole SO is riddled with threads that add two integers and then terminate, just so that the &amp;#x27;main&amp;#x27; thread can wait with &amp;#x27;join&amp;#x27;. God help us :(&lt;/i&gt;&lt;p&gt;I hope parallelSort() just calls sort() if the array is smaller than some threshold.</text></comment>