Java 8 Parallel Streams
Using Parallel Stream Java 8 streams comes with some convenience to do parallel processing by just calling the method parallel() or parallelStream() and all the magic happens behind the scene. But it comes with a price. If you are not careful about a few things it can actually backfire and cause problems with performance or may even cause concurrency problems or race conditions. A few things to take into consideration: Are the operations in the stream stateful or stateless? Consider the following example: words.stream() .filter( word->word.startsWith("a")||word.startsWith("e")||word.startsWith("i") ) .forEach(System.out::println); Here the filter operation is stateless operation because it only operates on one element at a time. It does not depend on any other elements to complete the operation. Consider the following. Inorder for the elements of the stream to be sorted…