Chapter 2. Concurrency on the JVM and the Java Memory Model
"All non-trivial abstractions, to some degree, are leaky." | ||
--Jeff Atwood |
Since its inception, Scala has run primarily on top of the JVM, and this fact has driven the design of many of its concurrency libraries. The memory model in Scala, its multithreading capabilities, and its inter-thread synchronization are all inherited from the JVM. Most, if not all, higher-level Scala concurrency constructs are implemented in terms of the low-level primitives presented in this chapter. These primitives are the basic way to deal with concurrency—in a way, the APIs and synchronization primitives in this chapter constitute the assembly of concurrent programming on the JVM.
In most cases, you should avoid low-level concurrency in place of higher-level constructs introduced later, but we felt it important for you to understand what a thread is, that a guarded block is better than busy-waiting, or why a...