ŷ

Jump to ratings and reviews
Rate this book

Java Concurrency in Practice

Rate this book
"I was fortunate indeed to have worked with a fantastic team on the design and implementation of the concurrency features added to the Java platform in Java 5.0 and Java 6. Now this same team provides the best explanation yet of these new features, and of concurrency in general. Concurrency is no longer a subject for advanced users only. Every Java developer should read this book."
--Martin Buchholz
JDK Concurrency Czar, Sun Microsystems

"For the past 30 years, computer performance has been driven by Moore's Law; from now on, it will be driven by Amdahl's Law. Writing code that effectively exploits multiple processors can be very challenging. Java Concurrency in Practice provides you with the concepts and techniques needed to write safe and scalable Java programs for today's--and tomorrow's--systems."
--Doron Rajwan
Research Scientist, Intel Corp

"This is the book you need if you're writing--or designing, or debugging, or maintaining, or contemplating--multithreaded Java programs. If you've ever had to synchronize a method and you weren't sure why, you owe it to yourself and your users to read this book, cover to cover."
--Ted Neward
Author of Effective Enterprise Java

"Brian addresses the fundamental issues and complexities of concurrency with uncommon clarity. This book is a must-read for anyone who uses threads and cares about performance."
--Kirk Pepperdine
CTO, JavaPerformanceTuning.com

"This book covers a very deep and subtle topic in a very clear and concise way, making it the perfect Java Concurrency reference manual. Each page is filled with the problems (and solutions!) that programmers struggle with every day. Effectively exploiting concurrency is becoming more and more important now that Moore's Law is delivering more cores but not faster cores, and this book will show you how to do it."
--Dr. Cliff Click
Senior Software Engineer, Azul Systems

"I have a strong interest in concurrency, and have probably written more thread deadlocks and made more synchronization mistakes than most programmers. Brian's book is the most readable on the topic of threading and concurrency in Java, and deals with this difficult subject with a wonderful hands-on approach. This is a book I am recommending to all my readers of The Java Specialists' Newsletter, because it is interesting, useful, and relevant to the problems facing Java developers today."
--Dr. Heinz Kabutz
The Java Specialists' Newsletter

"I've focused a career on simplifying simple problems, but this book ambitiously and effectively works to simplify a complex but critical subject: concurrency. Java Concurrency in Practice is revolutionary in its approach, smooth and easy in style, and timely in its delivery--it's destined to be a very important book."
--Bruce Tate
Author of Beyond Java

" Java Concurrency in Practice is an invaluable compilation of threading know-how for Java developers. I found reading this book intellectually exciting, in part because it is an excellent introduction to Java's concurrency API, but mostly because it captures in a thorough and accessible way expert knowledge on threading not easily found elsewhere."
--Bill Venners
Author of Inside the Java Virtual Machine

Threads are a fundamental part of the Java platform. As multicore processors become the norm, using concurrency effectively becomes essential for building high-performance applications. Java SE 5 and 6 are a huge step forward for the development of concurrent applications, with improvements to the Java Virtual Machine to support high-performance, highly scalable concurrent classes and a rich set of new concurrency building blocks. In Java Concurrency in Practice , the creators of these new facilities explain not only how they work and how to use them, but also the motivation and design patterns behind them.

However, developing, testing, and debugging multithreaded programs can still be very difficult; it is all too easy to create concurrent programs that appear to work, but fail when it matters most: in production, under heavy load. Java Concurrency in Practice arms readers with both the theoretical underpinnings and concrete techniques for building reliable, scalable, maintainable concurrent applications. Rather than simply offering an inventory of concurrency APIs and mechanisms, it provides design rules, patterns, and mental models that make it easier to build concurrent programs that are both correct and performant.

This book covers:


Basic concepts of concurrency and thread safety Techniques for building and composing thread-safe classes Using the concurrency building blocks in java.util.concurrent Performance optimization dos and don'ts Testing concurrent programs Advanced topics such as atomic variables, nonblocking algorithms, and the Java Memory Model

432 pages, Paperback

First published May 19, 2005

623 people are currently reading
4,243 people want to read

About the author

Brian Goetz

7books45followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
1,755 (60%)
4 stars
833 (28%)
3 stars
231 (8%)
2 stars
49 (1%)
1 star
18 (<1%)
Displaying 1 - 30 of 140 reviews
Profile Image for Erika RS.
829 reviews254 followers
December 29, 2012
Every programming language needs to have a book like Java Concurrency in Practice. I usually do not like books about specific programming languages because they tend to become obsolete so quickly. They are so specific to a particular version of a particular language that any small change renders them useless.

That is not the case with Java Concurrency in Practice. This book mixes general concurrency background and advice with Java specific advice with advice applicable to only certain versions of Java. Even as new versions of Java come out, this book will still have value (although not as much as at initial publication). Even as other languages become primary, there are still many parts of the book that will be worth rereading (but not all, which is why I say every language needs its own equivalent of this book).

Java Concurrency in Practice reads well. I found myself looking forward to reading it, which is not always the case with technical books. The organization built up knowledge gradually, making sure that a concept or library call was introduced before using it. In fact, the few times something, like join(), was brought up without introduction it was abnormal enough to be memorable.

The book starts with an introduction to concurrency. It first motivates the importance of concurrency: from here on out, speed-up comes mostly from having more cores. It then moves on to defining basic concepts such as thread safety, atomicity, locking, liveness, visibility, and publication. I feel like I have a reasonable background with concurrency in theory (although not in practice). Even so, I learned a lot from these introductory chapters. I usually considered concurrency primitives mainly as a way of controlling data access. I had not thought about the their relation to memory visibility, especially in the face of optimizing compilers.

The bulk of the book talks about techniques for building thread safe, reasonably performant programs. These rules are meant to make your programs safe and comprehensible. They may not squeeze the last bit of efficiency out of your code, but the authors strongly make the case that such optimization usually is not necessary. Clever tricks may make code faster, but they make it more likely to be wrong and harder to maintain. Furthermore, in the face of program optimization, hand tuned code may end up being slower than more naive code that has been optimized.

Instead, the authors advice programmers to write easy to understand and safe programs first and then find and optimize the bottlenecks. These range from low level rules such as favoring immutable objects whenever possible to high level guidance on how to structure programs (e.g., how fine grained should your concurrency be? Threads and context switching, while relatively cheap, are not free.)

Part of what makes this book great, however, is that the authors do not treat you like you are stupid. After spending most of the book helping you to understand the complexities of concurrency, they spend the last part of the book giving you the tools to shoot yourself in the foot. They realize that, just as sometimes it really is worth it to write assembly, sometimes performance requirements force you to use higher risk concurrency techniques. In this vein, the last chapters discuss explicit locks, custom synchronizers, nonblocking synchronization, and the Java memory model.

I highly recommend Java Concurrency in Practice to any Java programmer. Even if you are not explicitly using concurrency in your code, it shows up implicitly in enough libraries that it is worth reading at least the first part of the book. If you primarily program in another language, I would recommend that you find the equivalent book for your language of choice. Understanding concurrency is quickly becoming required knowledge for programmers.
Profile Image for snpefk.
76 reviews4 followers
August 11, 2019
Ожидал просветления � получил завуалированный вариант пасты "не лезь, блядь, дебил, сука, ебаный, она тебя сожрёт"
Profile Image for Algirdas Raščius.
30 reviews8 followers
January 26, 2012
Every Java developer should read this book.

There is a lot to learn from this book. And there is a lot of bad concurrent code written. World would be noticeably better, if every Java developer read this book before writing any concurrent code :)
Profile Image for Michael.
Author8 books592 followers
April 28, 2010
Wow, this was a damn fine book. For anyone exposed to the pre-Java5 concurrency support (implicit locking and volatile) this is an eye-opener. Goetz and company systematically deconstruct a bevy of poorly constructed "concurrent" source and provide tips and approaches to simplify concurrency in Java. The #1 point to take from this book is to avoid mutable data structures at all costs. Easier said than done of course, but much easier than lock-based concurrency.

-m
Profile Image for Christian.
2 reviews5 followers
January 2, 2021
Still in the process of reading this, but so far I've found it to be really approachable and a relatively easy read. Properly handling concurrency is a notoriously difficult problem but Brian Goetz spends a good amount of time going over it with not only practical Java examples, but also a good explanation of the underlying mechanisms that make it difficult to get correct which would be applicable to any programming language. Appreciate having the mix of clearly labeled "bad"/naive examples to approach concurrency + why they have issues along with the "correct" versions - and the trade-offs made by using different approaches.
396 reviews30 followers
May 15, 2019
Before I read this book, I thought, I already understand concurrency. How much Java-specific stuff can there be to learn? If I want to use some library, e.g. ConcurrentHashMap, I'll read its documentation before I use it. That should be good enough.

I was wrong. Partly this is because I didn't actually understand concurrency as well as I thought. I was used to thinking in terms of interleavings and ignoring reordering, which is insufficient! This led to some big surprises when reading possible program outputs in this book. But there was also a lot of stuff specific to the Java memory model covered here that I didn't know about, such as safe publication.

I'd say this book, or something else with equivalent Java-specific info, is a must-read for anyone developing concurrent programs in Java.
Profile Image for Ian Nelson.
7 reviews2 followers
November 26, 2011
This is an amazing book from both the software engineering and computer science perspectives. Having not learned much about concurrency from my degree program, and wanting to learn more, I turned to this book as a reference. There have been many reviews on this text, most positive, and I can definitely see why.

Although there is a *lot* of content to cover, it is very in-depth, and provides many examples to work through all of the conditions and failures that one may encounter.
Profile Image for Michael Koltsov.
109 reviews69 followers
December 11, 2014
It was quiet easy to review this book, because i try to re-read it every year and it had became a necessity for me. Some parts of it are not easy to comprehend but at the end of the day this book can teach you what no other book could.

This time i’ve created a repository that contains most of the examples. In my experience writing code helps me much more than reading code.

My score 5/5
Profile Image for Will.
87 reviews17 followers
April 16, 2010
Until I read this book, I was stuck on the early model of concurrent programming in Java. Basically, you had threads and you had synchronized methods. The performance characteristics of thread scheduling and lock acquisition were questionable in the early virtual machines, so I never bothered with them. The situation improved dramatically in Java 5, and Goetz et al. cover all the ins and outs.

Java Concurrency in Practice is much more than a reference to programming libraries and would be useful to anyone who knew Java and needed to understand parallel computing. The general principles should apply to other languages with little lost in translation. I read this book as a precursor to learning Clojure, a Lisp dialect that runs on the Java virtual machine, to better understand and appreciate its concurrency model.

Some complaints:
* At times, it's obvious that the book was the product of several authors.
* The forward references get in the way of an initial reading.
* The tenor of the book takes a few chapters to build and the organization is mysterious for awhile.
* You'll need to read the text closely and think about the examples to identify a set of "best practices." The authors give general guidelines but refrain from providing ready-made templates. That can be a problem if you just want to find a good starting point for your own code.

If you're a Java programmer, read this book. If you're a programmer who knows Java and who isn't familiar with approaches to concurrent execution, read this book. If you don't know Java, then this is not the place to start.
Profile Image for Thomas.
Author1 book58 followers
August 20, 2021
I can say that if you're doing anything concurrent on the JVM (and chances are that if you're doing anything on the JVM, you are), you should read this. It's a fantastic introduction to the mechanics of the system. Everything else you will find out there that presents alternate concurrency approaches (Akka, RxJava, etc.) builds on these basic underlying mechanics and understanding how they work will be an immense help.
Profile Image for Paul.
61 reviews7 followers
November 17, 2012
Anyone that even semi-seriously considers themselves a java programmer should have read this book, probably multiple times.
Profile Image for Dinesh Vijayakumar.
59 reviews1 follower
January 22, 2021
Extremely useful book IMHO. Glad that i was able to complete this book after multiple attempts previously. This book is a must for Java developers who want to understand the finer details of Concurrency, Synchronization, Atomic Variables, Java Memory Model, Safe Publication.

The book gradually progresses to advanced topics and the concepts were elucidated in greater detail with sample code. I feel confident in tackling concurrency related problems in Java. Plus i had a tour through the java.util.concurrent classes.

Some of the analogies used to explain ideas were near perfect. All in all, a great addition to your arsenal if you are a Long-Java dev.
Profile Image for dantelk.
191 reviews18 followers
September 2, 2024
Great book. However, I believe one has to have some prior knowledge of threads before jumping into this deep-dive book. Well, the first two sections were not really "deep" dive, but after the "testing" chapter, the topics quickly became more advanced.

I'd recommend following Jakob Jenkov's Youtube content on concurrency as a primer to this book.
Profile Image for Liana.
186 reviews3 followers
December 11, 2020
I had been trying to read this iconic book on Java concurrency for years, and today I've finally finished it.
The book itself is 5/5 and I've already used some tricks from it in my work.
However programming books are so hard to read, because it's really inconvenient to match the code and explanations.
Profile Image for Rostislav Vatolin.
17 reviews1 follower
October 24, 2020
I enjoyed reading this book by Brian Goetz. I learned a lot more than I knew about synchronization, locks, CAS, wait/notify, happens-before. I recommend.
16 reviews1 follower
May 8, 2022
Bit dated I think but the underlying concepts of concurrency it teaches are from the grounds-up. Took my own time to absorb and assimilate the concepts from thr book.. Every Java dev should read this book. Its that timeless classic
62 reviews
June 3, 2015
Book wonderfully covers ins and outs of concurrent programming in Java. Unfortunately, this book has won its renown due to one crucial factor - it one of the very few books covering this topic to such extent. Following this - the situation in which one-eyed is the king in the land of the blind is more than visual.

First and most definite problem with this book is the organisation of the material. To fully understand this book you have to read it at least twice. Why? Throughout the book the references to the forthcomming material are more than frequent. Either reorganising the material or giving reader basic information about the forthcomming material just in the place of its mentioning would diminish the severance of this problem.

Secondly, the book -being authored by the experts in the field - lack in detailed explanations of particular topics. While one sentence is more than enough for an expert, event a vivid and willingfull learner could feel like being left alone.

Thirdly, there are no exercises in the book, so there is no virtually no way to check the understanding of the material.

A chapter on the theoretical concepts of concurrency would be as well beneficial.

To some extent this disadvantages might be assigned to almost any technical book. Unfortunately, in case of JCiP they are more visual as nowadays almost all Java devs are focused on web solutions, so they usually have neither knowledge nor experience in the concurrent programming. The aforementioned disadvantages of the book make it practically unreachable for standard Java dev to read it with full understanding.
Profile Image for Jack Repenning.
77 reviews2 followers
December 23, 2010
This is a really crucial book for any Java developer. You may not realize you need it, but man oh man, you do![return][return]The Java culture and language development contain a trap: whereas it once was a commonplace that concurrent programming was too hard for "ordinary" developers, Java made it easy to do, and even in the beginning reasonably easy to do successfully.[return][return]Times have changed. Java programs used to run on uniprocessor machines (where "concurrency" is more an aspiration than a reality), and the Java virtual machine used to be relatively simple. Nowadays, even an inexpensive laptop has at least two cores, and can achieve real concurrency among half a dozen Java threads. The JVM has evolved aggressively to use this power, taking liberal advantage of feature always contained in the Java language specifications, but until now not necessary embodied in the JVM implementation. As a result, more and more, your programs do not mean what they appear to mean, and less and less are you free to presume they do.Fortunately, the principal and supporting authors here are the powerful minds behind the growth of the JVM's concurrency capabilities. And, a bit miraculously, these great minds, deeply embedded in this complex code, can and do explain its surprises and mastery in a way that should be accessible to any competent programmer. This is not "for Dummies" stuff, but it's also "not rocket science" (quite). You can handle this.[return][return]And, you must.
Profile Image for Yaroslav Dremanovich.
2 reviews1 follower
October 11, 2019
It took too much time to read it .. but it contains many theoretical parts and helps to set your mind in thinking in multi threads realty.. So, you will know how to safe publish objects, persist correctness of your program and speed up your program if it applicable by hardware.. One needs to read it once (no more). Despite that the book issued in 2006 - it is still actual in terms of manual handle of synchronization.
As for today - better way to improve performance of your code is to use JavaRx stack (but is has some disadvantages described in this book).
So... I recommend to read it once at least.
4 reviews3 followers
November 7, 2011
The book is definitely worth reading even if you do only develop enterprise applications, which get most of the concurrency from the application servers (at least will you understand how it works). You will get a deep understanding how does java.util.concurrent api works, why it is needed and when to apply one or another technique. The book is full of examples, guiding a reader from "bad" solutions to "better" and "best" solutions. Concurrency idioms are very well covered. I gave this book 5 star, which means that there are really a lot of wisdom, so I would reread the book some day again.
Profile Image for Craig.
62 reviews13 followers
September 8, 2011
As far as books on key programming topics go, this one is a gem. Insightful, relevant, and well written, serious Java developers ought to check this one out. Many of stickiest programming issues relate to threading or concurrency issues, and this book really comes through in outlining common mistakes, and offering great tips and solutions for the most common types of threading/asynchronous issues that tend to plague us.
Profile Image for Glen.
439 reviews40 followers
January 7, 2017
Very well done. Full of useful information, suggestions, and examples. I bought it for a specific question, found the answer right away and it was perfect! I could have tried much more complicated things, but this provided a simple solution that saved me a lot of time. I did not read it cover to cover.
Profile Image for Emil Petkov.
35 reviews4 followers
December 31, 2012
Brian Goetz is a concurrency czar - this gem taught me a lot about multicore development, non-blocking algorithms, threads, etc. The book is so deep and yet so practical that most of the other pieces on threading/concurrency seem like part of the "For Dummies" series.
Profile Image for Kenneth Blomqvist.
1 review6 followers
July 17, 2016
Goes into all the details of concurrent programming and explains the Java memory model and it's guarantees.

Highly recommended to any developer writing concurrent software (even if you don't use Java).
Profile Image for Martin Asenov.
34 reviews6 followers
September 26, 2012
Java concurrency in practice is one of the best programming-related books I have ever read (perhaps along with Effective Java, Java Puzzlers and Martin Fowler's refactoring).
Profile Image for Andrew Barchuk.
26 reviews
June 26, 2018
Very solid book despite not covering some more recent topics like fork-join concurrency, parallel Java 8 streams and RxJava.
1 review4 followers
August 23, 2017
I've heard this book referenced countless times in my career but never bothered to read it because I wasn't writing Java. Now I wish I had read it sooner.
Displaying 1 - 30 of 140 reviews

Can't find what you're looking for?

Get help and learn more about the design.