Is the Book ''Java Concurrency in Practice'' Still Relevant in the Era of Java 12?
After all the years and new Java releases, is this classic book still relevant?
Join the DZone community and get the full member experience.
Join For FreeOne of my readers, Shobhit, asked this question on my blog post about must-read advanced Java books: is the book "Java Concurrency in Practice" still relevant? I really liked the question and thought many Java programmers might have similar thoughts whenever someone recommends this popular Java read.
When this book was first published in 2006, the Java world was still not sure of about new concurrency changes made in Java 1.5. I think this was the first big attempt to improve Java's built-in support for multi-threading and concurrency.
Many Java programmers were even not aware of new tools introduced in the API, e.g. CountDownLatch
, CyclicBarrier
, ConcurrentHashMap
, and much more. The book offered them the seamless introduction of those tools and how they can use them to write high-performance concurrent Java applications.
Many Java developers will tell you that this book has become a bit dated in 2019, but my view is slightly different from most, and I still recommend Java Concurrency in Practice to any new Java developer or intermediate developers who want to master concurrency concepts.
The most important thing this book introduces is clear concepts and fundamentals of concurrent programming, e.g. visibility, ordering, thread-safety, immutability, parallelism, etc.
It also goes on to explain why most concurrent applications are incorrectly written in Java and the common mistakes made by Java programmers, which result in multi-threading issues like race conditions, deadlock, livelock, memory interference, and simply incorrect calculation.
Emoticons are used to show the bad practice before introducing the good and/or right way to do it, not only to correct the misconception many Java developers had before but to sow the seed of correct information pertaining to multi-threading and concurrency among Java developers.
There's no doubt that multi-threading and concurrency are difficult; they are both hard to get it right in code and hard to understand and explain. I have seen many programmers who simply weren't able to visualize how multiple threads are interacting with the same piece of code and different data.
It's much like the classical concept of recursion, which is too easy for some programmers but too difficult for others to grasp and apply in a real-world scenario.
The biggest contribution of the Java Concurrency in Practice to the Java world is not making concurrency easy but providing the correct and clear information which was lacking. Since I have taken a lot of interviews, I know that programmers always have misconceptions about threads and how they work.
Many programmers even with 4 to 5 years of experience in Java didn't understand how volatile variable works, what they know is that when you use a volatile variable it always check the value from main memory while comparing, which is the truth but not complete.
They were not told about the Java memory model and how volatile variable can affect the ordering of code and computing instructions behind code by JIT and JVM for optimization, which could result in subtle logical bugs.
They were not made aware of how volatile can guarantee the visibility of what was done by one thread prior to accessing volatile variable to other thread, etc. They don't know what is a memory barrier and how it impacts visibility.
Java Concurrency in Practice teaches those concepts to many Java programmers. In fact, I would admit that before reading that book, I had a lot of misconceptions about many essential multi-threading and concurrency concepts, e.g. ordering, visibility and subtle effect of final variables, and safe-publication, the book helped me to clear up those confusions.
If you find some sections of the book difficult to understand, then you are not alone. Thankfully, Dr. Heinz Kabutz's has simplified them in his Java Concurrency in Practice Bundle course, so check it out.
If you even think that is tough, then Mastering Threads is another course by Heinz that simplifies the multi-threading for beginner Java programmers.
Now, coming back to Java 8, yes from Java 1.5 to Java 8, the JDK added a lot of new tools to implement concurrency and design better Java concurrent applications. The introduction of fork-join pool in JDK 7, CompleteableFutures
in Java 8, and most importantly the new functional style of coding in Java 8 supported by the lambda expression.
You also got the stream and parallel stream, which allows developers to take advantage of concurrency without coding it. The overall idea of moving concurrency from application developer to API developers also makes it a little easier and reduced risk of implementing concurrency in Java.
It also means that now you can perform the bulk operation in Java with just a couple of methods and multiple threads without writing a single line of code involving threads, synchronized keyword, or wait-notify methods.
There's no doubt that Java developers have to learn these new tools to keep themselves up-to-date, and a books like Java 8 in Action really help on that front. It introduces you to all new changes in Java 8 and not only teaches you how to use them in your day-to-day task but also explains the motivation behind them to understand the bigger picture.
Even though Java Concurrency in Practice in its current state doesn't cover all these important concepts and tools, it's still an invaluable book to learn the fundamentals of threads, concurrency, and multi-threading tools supported by Java programming language.
It's still a must-read book for any Java developer who wants to learn and master multi-threading and concurrency, the biggest advantage of using Java for application development, in my opinion.
Java developers are thankful to Brian Goetz, Joshua Bloch, and all the authors for giving Java developers such a book to understand the confusing-but-critical concepts of multi-threading and concurrency.
Having said that, like many Java developers around the world, I would also love to see a newer, more up-to-date version of Java Concurrency in Practice to cover tools and methodologies introduced in Java 6, 7, 8, 9, 10,11,12, and maybe even in Java 13 in coming months, much like the updated version of Effective Java and Head First Design Pattern, which covers Java 8 and teaches you how certain patterns are easier to implement with new Java 8 features.
Thanks for reading this article! Please share your thoughts on Java concurrency and book recommendations in the comments below.
Published at DZone with permission of Javin Paul, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments