Concurrent Programming in Java, 2nd Edition surveys a wide field of research in parallelism and concurrency and shows how to do more with multithreading in Java with dozens of patterns and design tips. Written for the advanced Java developer, this book offers a comprehensive tour of leading-edge thinking about parallel coding processes. Within the dozens of techniques and tips offered here, this book accomplishes at least two goals. First, it shows how concurrency is implemented by default within Java, with material on how built-in features (like the synchronized keyword and its memory model) can be expected to perform when dealing with multiple threads. Naturally, Java threads themselves are also covered, including priorities, scheduling, and the like.Much of this book looks at ways to improve performance of concurrent code beyond the simple default strategies. After defining criteria for measuring concurrent code (such as safety and "liveness," a measure of running live threads effectively), the book presents dozens of techniques for letting threads work together safely. For the working Java programmer, coverage of patterns that have been implemented in the downloadable java.concurrency package will be the most immediately useful. (Within this nearly encyclopedic survey, short code snippets are used for every pattern and concept.)Though theoretical at times, this book offers plenty of ideas and sample code to get you started thinking of ways to improve multithreaded code.Impressively comprehensive, Concurrent Programming in Java offers a veritable bible of techniques for doing two things at once with threads in Java. It's a worthwhile guide to the state-of-the-art strategies for improving the performance of your Java threads. --Richard DraganTopics covered: Threads and concurrency in Java, design considerations (safety, liveness, and performance), Before/After Patterns, layering, adapters, immutability and synchronization, deadlock, resource ordering, the Java Memory Model and concurrency, using the java.concurrency package, confinement, refactoring for concurrency, mutexes, read-write locks, recovering from failure, notifications, semaphores, latches, exchanges, transactions, one-way messages, worker threads, polling and event-driven I/O, parallelism techniques (fork/join, computation trees, and barriers), Communicating Sequential Processes (CSP).
In this book, it covers a lot of different concurrent programming constructs. Some of these constructs are commonly known for Computer Scientists (things such as Binary/Counting Semaphores, fork/join, acquire/release constructs, latches.). Going into this book, I thought this would be more of a review of some of my Computer Science studies. I was pleasantly surprised to learn new terms and techniques to handle concurrency issues that I never would have thought of without reading this book. These examples all pleasantly surprised me, such as "Oh yea, I guess that would be useful to do in a situation like when you want to make sure that all systems in a distributed system are shut off."
One thing it was also nice to read is the trade-offs between using solution x versus solution y. In the real world (and in Computer Science, in general), there are constant tradeoffs. The age old example is "use more memory for the algo -or- wait more time for the algo to complete" is a common paradigm that software engineers need to make on a day-to-day basis. It is nice to hear from experience some of the trade-offs that need to be considered when using a technique described in the book.
I would have given this book a 5-star rating if it was not for one thing that continually irked me. As you are reading along, instead of referencing a concept in the book that may have already been mentioned or is going to be mentioned...it always referenced the Section Numbers. It was annoying and tedious to read. A sentence might be like this:
"While technique is used extensively, if you are looking for more flexibility in the framework that you use, refer to Section 2.3.2.3." Instead of giving me some pedantic section number, why don't you just say the section name? Say something like "or you could use techniques described in the Guarded Methods section to achieve the same results is a less complicated way.". The section numbers instead of the section names bugged me enough to remove 1 star from the review. I was thinking about removing 2 stars, but I think that was probably a bit too drastic.
One might wonder as I did if this work is still worth reading, given that Java concurrency in Practice (JCIP) is a more recent book, always recommended for concurrency in Java, and also has Doug Lea as one of its authors. And the answer is: very much so. Even though it’s a 1999 book, it is still surprisingly relevant. It shows its age at parts, e.g. in the use of raw types (generics were added in 2004 with Java 5), or when giving examples of SynchronizedInt and similar classes for what we now have AtomicInteger and siblings. But even so, as the book’s subtitle says, the book is about design principles and patterns, and luckily (or maybe obviously) these are timeless. And all this coming from a clear authority on the subject, given that he is the main author of the java.util.concurrent package (JSR 166).
Concurrent Programming in Java (CPJ) provides a mixture of theory and practice, and although the theory is solid (going over the usual topics such as safety and liveness concerns), the practice is what shines in it. The book shows different alternatives to solving problems, with many code samples, and discussions of the trade-offs of each design.
It’s likely that JCIP should be read first, in part so that the reader can more easily distinguish warnings that are no longer true (e.g. that Locks “may entail greater overhead since they are less readily optimized than are uses of built-in synchronization”). Also, because JCIP is more up-to-date. It goes over most of the java.util.concurrent utilities and when to use them, so it has more actionable advice for the average programmer.
CPJ instead relies more heavily on wait/notify patterns which are nowadays mostly discouraged in favor of the java.util.concurrent utilities (which were added later to the language thanks in great part to Doug Lea’s work). But if one needs to use wait and notify/notifyAll, I doubt there is a book with a bigger set of solid examples. Given that the book is previous to JSR 166, rather than going over the java.concurrent.package and how to use its utilities, the book deals more with how one would go about designing and implemeting such utilities, showing implementations of a Semaphore and a Semaphore with fairness guarantees (a FIFOSemaphore), a Lock (called Mutex in the book), etc.
A lot of techniques for designing and refactoring existing classes are also outlined, such as before/after designs, conflict sets, splitting locks, splitting classes, and the Specific Notification pattern, among many others. The book is also full of references, which is very useful for anyone wanting to dig deeper into the literature.
Well, it took me a very long time to finish this one :) A couple of months or so. Style of the book is very academic, and I had to re-read some passages many times (also I've got to mention that it is somewhat hard to read this book while riding the subway :)
I never had any problem with cross references, as other reviewer mentions. And I don't think it's not worth a read because it's too old and outdated, I think it's as useful as ever. It explains some basic stuff, it elaborates on Java memory model, on monitors, on how wait and notify really work internally, and also covers large number of design patterns and paradigms (and therefore it will be relevant as long as those patterns are used in practice).
So, my final word is: very useful book to read if you really want to understand how to write good and live and safe concurrent programs.
There is little you can get from this book if you have already read Java Concurrency in Practice and Java Threads. I don't think this is a good first book on the subject either. However, even though the book was written decades ago, it contains useful examples, ideas and patters which were eventually introduced and used in the Java concurrent package.
This is an excellent review of the concepts and ideas of concurrency in Java but I think it's a worthwhile read for every programmer. Partially this is because I think Java is one of the few general purpose languages that handles concurrent programming well.
The content is well written and concise. Would recommend.
A very good overview of concurrent programming in Java. I was worried that the book might be now obsolete, but most topics are covered in timeless manner. The book goes over basic concurrency constructs in Java such as synchronized, wait, notify. Then it uses them to show useful design pattern. And those pattern are generalised into higher level concurrency utilities. I like that everything is clearly explained. The author provide details which leads to certain design decision. What is useful in what context.