Is the book “Java Concurrency in Practice” relevant in the days of Java 8 and 11?
- Transfer
Hello colleagues!
The article, the translation of which we offer today, once again recalls the importance of the ageless book " Java Concurrency in practice ", authored by Brian Goetz.
The original comment dates for this article suggest that the author is not updating and republishing it for the first time. Therefore, we also allowed ourselves to update the link to the book mentioned in the article by Raul-Gabriel Urm, Mario Fusco and Alan Mycroft, which was published by Manning under the title Java 8 in Action. We are preparing a translation of a new edition called Modern Java. But for now, let's talk about the classics. You are invited to cat.
A reader with the nickname Shobhit asked me this question in the comments on an article about 12 advanced Java books for mid-level programmers - part 1 . The question is really good, and I think many Java programmers had similar doubts when in our time someone recommended reading “ Java Concurrency in Practice”". When this book first came out, in 2006, the whole Java world still could not figure out the competitiveness innovations made in Java 1.5. I think then the first serious attempt was made to improve Java's built-in support for multithreading and competitiveness. At that time, many programmers were not even aware of the new tools that appeared in the API, for example, CountDownLatch , CyclicBarrier ,
This is exactly the general idea of this book, and in this vein many developers will describe it to you if you ask, “How do you like Java Concurrency in Practice?” However, I take this book a little differently, and that is why I still recommend it to all beginners who are familiar with Java, or mid-level developers who want to master the concepts related to competition.
The most important material this book will introduce you to is clear concepts and fundamentals of competitive programming, in particular, visibility, ordering, thread safety , immutability , concurrency, etc.
She also explains why, in most cases, competitive Java applications are spelled incorrectly, why Java programmers make common mistakes that lead to multithreading problems, including race conditions, deadlock, active lock, memory interference, and simply incorrect calculations.
The book uses emoticons that accompany the description of “how to do it wrong” before introducing the reader to the correct and high-quality solution to the problem. So the book not only helps to deal with the misconceptions that many Java developers have, but also to instill in the Java community the right information on how to work with multithreading and competition.
There is no doubt that multithreading and competition are complex. They are not easy to implement correctly in code; it is equally difficult to understand and explain. I know many programmers who are simply not able to clearly depict how different threads interact with the same code element, operating with different data.
Like the classic recursion example, multithreading is very easy for some programmers to practice, while for others, multithreading is difficult to comprehend and apply in an application scenario.
The greatest contribution of the Java book Concurrency in Practice to the development of the Java world is not to simplify competition, but to provide true and accurate information about it that was lacking. Since then I have conducted many interviews and I know that programmers always do not quite accurately imagine the structure of flows and how they work.
Many programmers who even managed to work with Java for 4-5 years do not understand how volatile variables are arranged ; all they know is that when working with a mutable variable, it is necessary to check with each comparison what value is in the main memory. This is true, but only part of the truth.
They were not told about the Java memory model, about how a variable variable can affect the order of the code and the execution of computational instructions at its core. It is about using dynamic compilation ( JIT ) and the Java virtual machine ( JVM ) for optimization; such optimization can lead to subtle logical errors.
People are not told how mutable variables allow you to see what was done in one thread before accessing a variable from another thread, etc. Not everyone knows what a memory barrier is and how it affects visibility.
It was from the book Java Concurrency in Practice that many Java programmers learned all these concepts. I must admit that I myself, until I read it, was largely mistaken about many significant issues of multithreading and competitiveness, in particular, the sequence, visibility and implicit effects of the final variables and safe publication. The book helped me figure this out.
By the way, if some sections of the book seem a little incomprehensible to you - believe me, not to you alone. Here we thank Dr. Heinz Kabutz, who presented the material of the book in a simplified form in his Java Concurrency in Practice Bundle course .
Even if you find this material too complicated, Heinz has another course, Mastering Threads, which helps to understand the multithreading of any average Java programmer.
Now let's talk about Java 8, that is, what has changed from Java 1.5 to Java 8. A lot of new tools have appeared in the JDK to introduce competitiveness and design better competitive Java applications. The fork-join pool has appeared in JDK 7 , in Java 8 -
We also have streams and parallel streams, allowing developers to take advantage of competitiveness without programming it. The whole idea of taking the implementation of competition from application developers and delegating it to the developers of the API slightly simplifies the situation with competition in Java and reduces the risks of its implementation.
This also means that in Java you can perform bulk operations in multiple threads using just a couple of methods, without writing a single line of code related to threads, the synchronized keyword, or wait and notify methods.
Undoubtedly, any Java developer needs to learn these new tools in order to keep up with the development of technology - which, of course, will help a book like “Modern Java In Action . " It will not only introduce you to all the innovations of the Java language, but also help you learn how to use them in everyday tasks, understand the motivation for these innovations and get a general idea of the modern Java language.
Although the book Java Concurrency in Practice in its current form does not cover all of these important concepts and tools, it nevertheless remains invaluable for exploring the key features of the Java language related to threads , competition, and multithreading .
Götz’s book is still a must-read for any Java developer who wants to learn and master multithreading and competitiveness — Java’s greatest strengths in application development.
Based on the foregoing, I, like many Java developers around the world, would like to see the updated edition of Java Concurrency in Practice, which would consider the tools and methodologies that appeared in Java 6, 7, 8, 9, 10 and maybe even in Java 11. After all, updated versions of Effective Java and Head First design patterns have appeared , covering Java 8 and demonstrating how much easier it is to implement various patterns with the new features of Java 8.
The article, the translation of which we offer today, once again recalls the importance of the ageless book " Java Concurrency in practice ", authored by Brian Goetz.
The original comment dates for this article suggest that the author is not updating and republishing it for the first time. Therefore, we also allowed ourselves to update the link to the book mentioned in the article by Raul-Gabriel Urm, Mario Fusco and Alan Mycroft, which was published by Manning under the title Java 8 in Action. We are preparing a translation of a new edition called Modern Java. But for now, let's talk about the classics. You are invited to cat.
A reader with the nickname Shobhit asked me this question in the comments on an article about 12 advanced Java books for mid-level programmers - part 1 . The question is really good, and I think many Java programmers had similar doubts when in our time someone recommended reading “ Java Concurrency in Practice”". When this book first came out, in 2006, the whole Java world still could not figure out the competitiveness innovations made in Java 1.5. I think then the first serious attempt was made to improve Java's built-in support for multithreading and competitiveness. At that time, many programmers were not even aware of the new tools that appeared in the API, for example, CountDownLatch , CyclicBarrier ,
ConcurrentHashMap
and many others. The book served them as a debugged introduction to working with these tools, and told how they can be used to write high-performance, competitive Java applications.This is exactly the general idea of this book, and in this vein many developers will describe it to you if you ask, “How do you like Java Concurrency in Practice?” However, I take this book a little differently, and that is why I still recommend it to all beginners who are familiar with Java, or mid-level developers who want to master the concepts related to competition.
The most important material this book will introduce you to is clear concepts and fundamentals of competitive programming, in particular, visibility, ordering, thread safety , immutability , concurrency, etc.
She also explains why, in most cases, competitive Java applications are spelled incorrectly, why Java programmers make common mistakes that lead to multithreading problems, including race conditions, deadlock, active lock, memory interference, and simply incorrect calculations.
The book uses emoticons that accompany the description of “how to do it wrong” before introducing the reader to the correct and high-quality solution to the problem. So the book not only helps to deal with the misconceptions that many Java developers have, but also to instill in the Java community the right information on how to work with multithreading and competition.
There is no doubt that multithreading and competition are complex. They are not easy to implement correctly in code; it is equally difficult to understand and explain. I know many programmers who are simply not able to clearly depict how different threads interact with the same code element, operating with different data.
Like the classic recursion example, multithreading is very easy for some programmers to practice, while for others, multithreading is difficult to comprehend and apply in an application scenario.
The greatest contribution of the Java book Concurrency in Practice to the development of the Java world is not to simplify competition, but to provide true and accurate information about it that was lacking. Since then I have conducted many interviews and I know that programmers always do not quite accurately imagine the structure of flows and how they work.
Many programmers who even managed to work with Java for 4-5 years do not understand how volatile variables are arranged ; all they know is that when working with a mutable variable, it is necessary to check with each comparison what value is in the main memory. This is true, but only part of the truth.
They were not told about the Java memory model, about how a variable variable can affect the order of the code and the execution of computational instructions at its core. It is about using dynamic compilation ( JIT ) and the Java virtual machine ( JVM ) for optimization; such optimization can lead to subtle logical errors.
People are not told how mutable variables allow you to see what was done in one thread before accessing a variable from another thread, etc. Not everyone knows what a memory barrier is and how it affects visibility.
It was from the book Java Concurrency in Practice that many Java programmers learned all these concepts. I must admit that I myself, until I read it, was largely mistaken about many significant issues of multithreading and competitiveness, in particular, the sequence, visibility and implicit effects of the final variables and safe publication. The book helped me figure this out.
By the way, if some sections of the book seem a little incomprehensible to you - believe me, not to you alone. Here we thank Dr. Heinz Kabutz, who presented the material of the book in a simplified form in his Java Concurrency in Practice Bundle course .
Even if you find this material too complicated, Heinz has another course, Mastering Threads, which helps to understand the multithreading of any average Java programmer.
Now let's talk about Java 8, that is, what has changed from Java 1.5 to Java 8. A lot of new tools have appeared in the JDK to introduce competitiveness and design better competitive Java applications. The fork-join pool has appeared in JDK 7 , in Java 8 -
CompleteableFutures
. It is much more important that, starting with Java 8, a new, more functional programming style provided by lambda expressions has become fixed .We also have streams and parallel streams, allowing developers to take advantage of competitiveness without programming it. The whole idea of taking the implementation of competition from application developers and delegating it to the developers of the API slightly simplifies the situation with competition in Java and reduces the risks of its implementation.
This also means that in Java you can perform bulk operations in multiple threads using just a couple of methods, without writing a single line of code related to threads, the synchronized keyword, or wait and notify methods.
Undoubtedly, any Java developer needs to learn these new tools in order to keep up with the development of technology - which, of course, will help a book like “Modern Java In Action . " It will not only introduce you to all the innovations of the Java language, but also help you learn how to use them in everyday tasks, understand the motivation for these innovations and get a general idea of the modern Java language.
Although the book Java Concurrency in Practice in its current form does not cover all of these important concepts and tools, it nevertheless remains invaluable for exploring the key features of the Java language related to threads , competition, and multithreading .
Götz’s book is still a must-read for any Java developer who wants to learn and master multithreading and competitiveness — Java’s greatest strengths in application development.
Based on the foregoing, I, like many Java developers around the world, would like to see the updated edition of Java Concurrency in Practice, which would consider the tools and methodologies that appeared in Java 6, 7, 8, 9, 10 and maybe even in Java 11. After all, updated versions of Effective Java and Head First design patterns have appeared , covering Java 8 and demonstrating how much easier it is to implement various patterns with the new features of Java 8.