5 ms·
As someone who has done a lot of parallel programming, I really can't recommend Java 8 streams enough. They have a bit of overhead, however, they are incredibly
by slaymaker1907 9y ago
As someone who has done a lot of parallel programming, I really can't recommend Java 8 streams enough. They have a bit of overhead, however, they are incredibly easy to use and are extremely expressive.
- RodgerTheGreat 9y agoI've done some tinkering with streams, and I was initially very excited. They do come with some frustrating limitations. Foremost in my mind: Concatenation of streams is fairly straightforward, but how do I perform a parallel join (zip?) of multiple streams? In other words, given [1,2,3] and ["A","B","C"], how do I map over [[1,"A"],[2,"B"],[3,"C"]]?
- dahauns 9y agoAFAIK this isn't possible yet in a straightforward way, and it boils down to limitations of the type system (lack of tuples resp. value types in general), and the (understandable) refusal of many to do it in way that's hacky and potentially slow. The discussion about this is actually quite old, for example: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-observers/2013-June/002046.html http://mail.openjdk.java.net/pipermail/lambda-libs-spec-obse... IIRC that's a problem on bytecode level, that's why a (clean) solution still hasn't come up yet.
- nmg 9y agoIn the talk "Clojure Concurrency" [1], Rich Hickey demands that everyone in the room read "Java Concurrency in Practice" [2]. "It will scare the crap out of you." [1] https://youtu.be/dGVqrGmwOAw?t=23m57s https://youtu.be/dGVqrGmwOAw?t=23m57s [2] https://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601/ https://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz...
- muxator 9y agoWhat do that comment mean?
- peheje 9y agoJava 8 released march 2014. Youtube video published december 2012. Book originally published 2006. What am I missing?
- cle 9y agoThe fact Java 8 streams only address a tiny sliver of the concurrency problems addressed by JCIP. In practice, Java 8 parallel streams are generally discouraged outside of raw number crunching, which is rarely where we need parallel speedup anyway.
- Coding_Cat 9y agoraw number crunching doesn't parallel speedup(!)?
- phdelightful 9y agoThe parent might be saying that we already have some good techniques for speeding up raw number crunching in parallel, so it's not as desirable to add yet another.
- cle 9y agoDidn't say that, I said that we rarely need parallelization for raw number crunching. Developers use parallelization for coordinating expensive IO way more often, and Java 8 streams solve almost nothing for that. Still need to know and worry about other Java concurrency primitives like volatiles, monitors, thread pools, etc. and all their pitfalls (race conditions, deadlocks, etc.). You should still read JCIP, it is still highly relevant in Java-land. Java 8 streams solved almost nothing in terms of concurrency (in fact they probably created more problems than they solved...). You should still be scared of concurrency in general, and particularly in Java. And you should definitely consider a different language with more sane and modern concurrency primitives if you really need concurrency.
- peheje 9y agoAh ok. I was confused by the reponse to slaymaker1907 who recommended Streams directly, as it didn't seem to address the Stream API. I guess many of the challenges of concurrent computing still applies here. When else do we need parallel speedup?