Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors
More than ever, learning to program concurrency is critical to creating faster, responsive applications. Speedy and affordable multicore hardware is driving the demand for high-performing applications, and you can leverage the Java platform to bring these applications to life.
Concurrency on the Java platform has evolved, from the synchronization model of JDK to software transactional memory (STM) and actor-based concurrency. This book is the first to show you all these concurrency styles so you can compare and choose what works best for your applications. You’ll learn the benefits of each of these models, when and how to use them, and what their limitations are.
Through hands-on exercises, you’ll learn how to avoid shared mutable state and how to write good, elegant, explicit synchronization-free programs so you can create easy and safe concurrent applications. The techniques you learn in this book will take you from dreading concurrency to mastering and enjoying it. Best of all, you can work with Java or a JVM language of your choice – Clojure, JRuby, Groovy, or Scala – to reap the growing power of multicore hardware.
If you are a Java programmer, you’d need JDK 1.5 or later and the Akka 1.0 library. In addition, if you program in Scala, Clojure, Groovy or JRuby you’d need the latest version of your preferred language. Groovy programmers will also need GPars.
List Price: $ 35.00
Price: $ 18.95


An important work on a challenging topic,
This book should be considered part of a two book series along with Venkat’s 2009 book “Programming Scala: Tackle Multi-core Complexity on the JVM”. The earlier book was a relatively short (250 pages versus 852 pages for Oderski’s Scala book), perhaps too short, overview of Scala. It’s 12 chapters skip over lots of the details in Oderski’s 18 chapter book, and contains only a single chapter on Concurrent Programming.
By comparison the new book is all about Concurrent Programming models and attempts to be agnostic about the JVM language to be used. Most examples are first given in Java, then a simpler way is shown to do it in Scala, and then often a short section saying how the example could be done in Ruby.
The book describes the difficulties of concurrent programming in JVM languages especially given the rise of multi-core processors. It then describes three “solutions”: the naïve Java approach, Software Transactional Memory and Actors. It should be noted that the Actors chapter is based on Akka, so if you don’t care for Akka you may not like this book.
The Power and Perils of Concurrency – This should be an unsurprising recap of well known problems; if you’re reading this book you will almost certainly have run into the problems listed here already.
Strategies for Concurrency – Talks about ways to divide problems into parts that can be computed independently
Modern Java/JDK Concurrency – This talks in detail about the changes made to the Java libraries to better support concurrency, specifically things like using ExecutorService rather than “new Thread()” and using Lock vs. synchronized. Interestingly though the chapter fails to discuss the little known but serious differences between synchronized blocks and methods involving fairness and barging.
Taming Shared Mutability – This chapter begins to offer the Scala kool-aid of mutability is bad. Reading this chapter is made easier if you’ve already read Goetz’s “Programming Concurrency”.
Software Transactional Memory – This chapter talks about Clojure’s STM model and how to use it in Java via Akka. Its an interesting chapter but one that will feel odd if you’re a programmer also coming to terms with non-relational databases. As databases move away from the transitional transactional model here comes STM bringing transactions to mutable variables.
Actor-based Concurrency – Actors are basically a message passing schema where immutable messages are passed between lightweight actors (thread-like). Just as you can use thread pools to reduce the cost of threads there are what amount to actor pools which lighten their cost. It does require some rethinking to embrace the actor approach.
Overall this is a fine book that brings quite a lot to the table. My only reservation would be that if you are a seasoned Java programmer you might take the first four sections as a given and jump right to the Actors approach. And if you’re not a seasoned Java programmer you probably don’t realize how badly you need this book.
Was this review helpful to you?
|Skimpy,
I am a veteran Java programmer, looking to move into Scala, using Akka actors. As “Actors in Scala” wasn’t released yet, this looked like the best choice. Unfotunately, the “language neutral” aspect of the book will probably satisfy no one. Too much space is used to repeat the same concepts, but in different languages. Particularly annoying was a section on actors, in which a problem is first implemented in Java, then Scala; then we are shown the use of Typed Actors (which are conceptually very similar to untyped actors) to implement the same problem, again in both Java and Scala (making that 4 detailed implementations and explanations of the same problem, instead of highlights of the important differences). This like a freshman padding out his term paper.
I was hoping for a book that would go into deep concepts related to actors and STM. This is more of an introduction to modern JVM concurrency idioms, with a few variations on the usual highly simplified programming examples one can find on web blogs, such as the obligatory bank account implementation.
Still, there were some interesting bits of theoretical background which I did not know, such as the formula for determining the number of threads to use in an application based on how compute-bound the tasks are.
Was this review helpful to you?
|