I've recently been learning about various libraries for concurrency in Java such as ConcurrentHashMap
and the lovely non blocking one from Cliff Click
I don't know much about Scala but I've heard good things about the recent parallel collections library.
I'd like to know what are some major advantages that this library would give over Java based libraries?
The design of Scala's parallel collections library is inspired by and deeply integrated with Scala's (sequential) collections library (introduced in 2.8). It provides a parallel counterpart to a number of important data structures from Scala's (sequential) collection library, including: ParArray. ParVector. mutable.
Scala programming language already brings us a collection to quickly implement parallel computing, the Parallel Collections. In this tutorial, we'll check out some concepts of parallelism with Scala and the usage of parallel collections.
Scala concurrency is built on top of the Java concurrency model. On Sun JVMs, with a IO-heavy workload, we can run tens of thousands of threads on a single machine. A Thread takes a Runnable. You have to call start on a Thread in order for it to run the Runnable.
The two collections are for different uses.
Java's concurrent collections allow you to use them from a parallel context: many threads can access them simultaneously, and the collection will be sure to do the right thing (so the callers don't have to worry about locks and such).
Scala's parallel collections, in contrast, are designed to run high-order operations on themselves without you having to worry about creating threads. So you can write something like:
myData.par.filter(_.expensiveTest()).map(_.expensiveComputation())
and the filter and map will each execute in parallel (but the filter will complete before the map starts).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With