In this chapter, we covered the different ways that are available if you want to perform parallel programming in Scala. The ways covered are: using JVM threading primitives, Scala's parallel collections, and the Akka framework.
The JVM threading primitives give a low-level access to the threading capabilities of JVM, but are prone to various problems inherent in most such threading API's. We saw how to write simple programs using the Thread
class and how to avoid race conditions via the use of the synchronized
statement.
We then explored Scala's parallel collections—parallelized versions of most collection classes. These work by executing various functional programming operations in parallel. Examples include, map
, fold
, and so on.
We saw how one can use this to very simply parallelize programs that use large collections and rely on functional programming operators. Finally, we scratched the surface of the massive Akka framework for actor-based concurrent programming. The framework...