Monday, January 30, 2012

Book Review: Programming Concurrency on the JVM

Programming concurrency is a tough task to get right, just ask Venkat, he'll tell you so!  I attended a presentation by Dr. Venkat Subramaniam on this very subject, Concurrency on the JVM, at my local Java user group a couple months ago and he really caught my attention.  The presentation was a condensed version of the book, and needless to say, I bought the book to help fill in all the details.

Not only is Venkat a 'subject matter expert',  but his presentation kept everyone engaged and laughing!

The book is broken down in 5 parts, with 10 chapters total, at just over 250 pages.  The main sections of the book are:

  • Strategies for Concurrency - this discusses the impact of multi-core machines and the three design approaches that are discussed throughout the rest of the book, Shared Mutability, Isolated Mutability and Pure Immutability.

  • Modern Java/JDK Concurrency - covers the Java 1.5+ concurrency features and talks about how to use the newer concurrency classes, like ExecutorService, CountDownLatch, Locks and Fork/Join to solve concurrency problems.

  • Software Transactional Memory - covers Software Transactional Memory (STM), popularized by Clojure, which places access to memory within transactions.  STM is one option for getting away from the 'Synchronize and Suffer' model as Venkat call it.  The intention is to make threaded code more deterministic.   Using the JDK concurrency tools, there is no way to be sure you code is correct because it doesn't always fail when/where you need it to.   By putting the memory access inside transactions, the transaction manager helps resolve the conflicts without explicit locking.

  • Actor-based Concurrency - covers actor design approaches as another option for concurrency design without using synchronization.  This section exercises actors from the Akka library from Scala, Actors from the Groovy library GPars, and mixing Actors and STM as a possible solution.

  • Epilogue - is a short recap of the topics presented previously and points out the scenarios when each of the solutions would be appropriate.
The book lays out a couple example problems and then develops solutions for these problems across a range of JVM languages (Java, Groovy, Scala, Clojure and JRuby).   The examples are short and concise,   enough to help you to get started prototyping against your own concurrency issues.

This is a good book to get you started on some of these newer concurrency concepts and libraries.  It was an easy read, and I completed the reading fairly quickly, as opposed to the "Java Concurrency in Practice" book, which I started and stopped twice and still have not completed yet!

I would recommend this book to anyone looking to improve their programming skills in the concurrency area.  The book provides you with some alternatives to the old standby of ' Synchronize and Suffer' model.
My last recommendation, if you get the opportunity, attend one of Venkat's presentations, you won't be sorry!

1 comment: