Chapter 5. Concurrency
Concurrency was one of the chief design goals of Clojure. Considering the concurrent programming model in Java (the comparison with Java is due to it being the predominant language on the JVM), it is not only too low level, but rather tricky to get right that without strictly following the patterns, one is more likely to shoot oneself in the foot. Locks, synchronization, and unguarded mutation are recipes for the concurrency pitfalls, unless exercised with extreme caution. Clojure's design choices deeply influence the way in which the concurrency patterns can be achieved in a safe and functional manner. In this chapter, we will discuss:
- The low level concurrency support at the hardware and JVM level
- The concurrency primitives of Clojure—atoms, agents, refs and vars
- The built-in concurrency that features in Java safe, and its usefulness with Clojure
- Parallelization with the Clojure features and reducers