Saturday, May 4, 2024

Is "Java Concurrency in Practice" still Valid in the Era of Java 21?

Hello guys, one of my reader Shobhit asked this question on my blog post about 12 must-reads advanced Java books for intermediate programmers - part 1. I really like the question and thought that many Java programmers might have the same doubt whenever someone recommends them to read Java Concurrency in Practice. When this book came first in 2006, Java world was still not sure of about new concurrency changes made in Java 1.5, I think 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 like 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.

This is the general view of the book, which many Java developer will give you when you asked them about how did you find "Java Concurrency in Practice", but mine view is slightly different from them and that's the main reason 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 introduce was clear concepts and fundamentals of concurrent programming like 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 right way to do helped a lot not only to correct the misconception many Java developers had before but to sow the seed of right information pertaining to multi-threading and concurrency among Java developers.

No doubt that multithreading 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 with different data.

Much like the classical concept of recursion which is too easy for some programmers but too difficult for others to grasp and apply in the 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.




Why Read Java Concurrency in Practice? Is it still valid in the era of Java 21?

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 checks 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 variables 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 variables to other thread etc. They don't know what is a memory barrier and how does it impact visibility.

The Java Concurrency in Practice book teaches those concepts to many Java programmers. In fact, I would admit that before reading that book, I have lots of misconceptions about many essential multi-threading and concurrency concepts like ordering, visibility, and subtle effect of final variables and safe-publication, the book helped me to clear those.

And, because of that I think Java Concurrency in Practice still valid as these are fundamental concepts and haven't changed even in Java 17, though an update will definitely make this book even better. Btw, if you find some sections of the book difficult to understand then you are not alone, but thankfully Dr. Heinz Kabutz has simplified them in his Java Concurrency in Practice Bundle course.

Is "Java Concurrency in Practice" still valid in  era of Java 10?


If you think even that is tough then Mastering Threads is another course by Heinz, which simplifies the multithreading for average Java programmer. He is also offering a 30% discount until the 19th of February.

Now, coming back to Java 8, yes from Java 1.5 to Java 8, JDK has a lot more new tools to implement concurrency and design better Java concurrent application. The introduction of the fork-join pool in JDK 7, CompletableFutures 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 the 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.

No doubt, that Java developer has to learn these new tools to keep themselves up-to-date and a book like Head First Java 3rd Edition (Updated for Java 17) really helps on that front. It introduces you to all new changes in Java 8 and 17 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.

best book to learn Java for beginners


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.

Java developers are thankful to Brian Goetz, Joshua Bloch, and all the authors for giving Java developer such an authority book to understand the confusing but critical concepts of multithreading 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 13, 14, 15, 16, 17 and maybe in Java 18 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.


Other Articles You May Like to Explore

Thanks for reading this article so far. If you also love to see a new and updated version of Java Concurrency in Practice much like Head First Java, Algorithms, and Head First Design Pattern then please share this article on Facebook and Twitter and maybe our request will reach to Brian and the publisher of the book.

P.S. - Let's hope Brian Goetz and other authors of the book listen to this request and gift Java developers around the world with a new version of Java Concurrency in Practice  until then Dr. Heinz Kabutz' Java Concurrency in Practice Bundle can be used to keep yourself up-to-date.

Now, over to you? what is your favorite Java book? and Have you read the Java Concurrency in Practice yet?

3 comments:

  1. Interesting article... As an intermediate Java programmer that has yet to learn how to use concurrency, I now see that perhaps it is a good idea to brush off the concepts and delve into Java 8 lambda expressions rather than train methodically to master concurrency and its best practices as introduced in Java 1.5.
    If it is possible to have your feedback, I'd like to know what you think?

    ReplyDelete
  2. Hello @unknown, I won't advise that. If you don't know how concurrency works, how Java memory model works, how thread interact with each other, what change they can see and what they cannot see, then you would face numerous challenges while coding, debugging or maintaining Java application. You should first learn those.

    Also, lambda expression is independent of concurrency, you can still learn how to use that while learning concurrency and multithreading fundamentals.

    ReplyDelete
  3. Hi,
    The link to Dr. Heinz Kabutz' Java Concurrency in Practice Bundle is not working. It is 403
    Could you please share updated url if it exists

    ReplyDelete