Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors
By Venkat Subramaniam
(Pragmatic Bookshelf, paperback, list price $35.00)
“Faster!”
That’s the word pressuring many programmers today as modern multicore hardware makes it possible to perform numerous actions simultaneously.
“A concurrent program may download multiple files while performing computations and updating the database,” notes the author of this well-written introduction to programming concurrency on the Java Virtual Machine (JVM).
So speed increasingly is of the essence, but so is improving how well (and quickly) applications respond to users.
In Programming Concurrency on the JVM, the focus is on introducing Java programmers to “three separate concurrency solutions—the modern Java JDK [Java Development Kit] concurrency model, the Software Transactional Model (STM), and the actor-based concurrency model.” And the goal is to help programmers learn the advantages and disadvantages of each and make the right choices for their applications.
The author states that “[t]here are three ways to avoid problems when writing concurrent programs:
- Synchronize properly.
- Don’t share state.
- Don’t mutate state.”
He explains that “[i]f we use the modern JDK currency API [application programming interface], we’ll have to put in significant effort to synchronize properly. STM makes synchronization implicit and greatly reduces the changes of error. The actor-based model, on the other hand, helps us avoid shared state. Avoiding mutable state is the secret weapon to winning concurrency battles.”
Programming Concurrency on the JVM is adequately illustrated and divided into five parts: Strategies for Concurrency, Modern Java/JDK Concurrency, Software Transactional Memory, Actor-Based Concurrency, and an epilogue focusing on making the right choices.
The book, the author stresses, is not for Java newcomers. It is for “experienced Java programmers who are interested in learning how to manage and make use of concurrency on the JVM, using languages such as Java Clojure, Groovy, JRuby, and Scala.”
Most of the code examples are in Java, but he includes some examples in Clojure, Groovy, JRuby, and Scala, as well. And he has made extra effort “to keep the syntactical nuances and the language-specific idioms to a minimum.”
He adds: “Programming concurrency is hard, yet the benefits it provides make all the troubles worthwhile.”
— Si Dunn