Home - Java
Java Concurrency in Practice
Price: $47.99
& 2-Day * Free Nationwide Shipping! (* details)
Availability: Usually ship in 24 hours if sold by Amazon.com
Product Details
| Binding: | Kindle Edition |
|---|---|
| EAN: | |
| Label: | Addison-Wesley Professional |
| Feature: | |
| Publisher: | Addison-Wesley Professional |
| Studio: | Addison-Wesley Professional |
Editorial Reviews
This is the eBook version of the printed 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 faci...
Customer Reviews
This book is not meant to be an introduction to concurrency in Java. Its intention is to offer practical design rules to assist developers in the difficult process of creating safe, fast, and high-performance concurrent classes. While many of the general concepts in this book are applicable to versions of Java prior to Java 1.5, most of the code examples and all the statements about the Java Memory Model assume Java 1.5 or later. By "later" I mean that some of the code examples use library features added in the not-yet released Java 1.6. After the introduction, which consists of Chapter 1, the book is divided into four parts:
Part one, "Fundamentals", (Chapters 2-5) are about the basic concepts of concurrency, thread safety, and composing thread-safe classes from those concurrent building blocks provided by the Java language. Chapter 2, "Thread Safety", and 3, "Sharing Objects", include nearly all of the rules on avoiding concurrency hazards, constructing thread-safe classes, and verifying thread safety. Thus, these chapters emphasize theory and have less code than other chapters in the book. Chapter 4 , "Composing Objects", covers techniques for composing large thread-safe classes from smaller thread-safe classes. Chapter 5, "Building Blocks", covers thread-safe collections and synchronizers, which are the the concurrent building blocks provided by Java. To conclude the section, the authors work through the steps of building an efficient, scalable result cache that could be used in a web server. A summary of the most important rules presented in Part one occur at the end of the section.
Part two, "Structuring Concurrent Applications", describes how proper use of threading improves the throughput and responsiveness of concurrent applications. The topics covered in this section include identifying tasks that can be run in parallel and programming them as such, proper termination of tasks, using thread pools for greater efficiency in multi-threaded systems, and finally improving the responsiveness of single-threaded systems, GUI's being the most prominent example.
Part 3, "Liveness, Performance, and Testing" is concerned with ensuring that concurrent programs actually do what is expected of them and do so with acceptable performance. The authors describe how to avoid situations where a thread waits forever, also known as a "liveness failure". Also included in this section is an excellent explanation of the use of the "ThreadLocal" class and how it makes it much easier to manage the process of associating a thread with its per-thread data.
Part 4, "Advanced Topics", covers issues that will probably be interesting only to experienced developers. These topics include explicit locks, atomic variables, nonblocking algorithms, and developing custom synchronizers. Any of these techniques, explicit locks in particular, can cause chaos when done incorrectly. This book shows how to use these techniques safely and with confidence.
One of the things that makes this book so good are the many code examples. There are only snippets of entire programs included in the book itself in order to highlight the portions relevant to the concurrency issue being discussed. The code examples are either good examples, questionable examples, or bad code examples and are decorated with "Smiley Faces" that are either happy, concerned, or unhappy depending on the quality of the code. The full versions of the code examples, as well as supplementary examples and errata, are supposed to be available from the book's website. However, at the time I am writing this, they are not yet available.
Overall, I would say that this is the most complete and accessible resource on concurrency in Java I have seen in print. I highly recommend it.
Before tackling this book, you should have at least some idea of pre-Java 5.0 concurrency. You don't need to be a threading master, though, as the first part of the book covers basics like deadlock, atomicity and liveness. This was my favourite part of the book, as it comes with lots of small code snippets, both right and (horribly) wrong, and pithy design guidelines. It's rather like Effective Java in that respect - although the material on threading was probably the weakest part of that book, so this is a definite improvement.
The second part deals with thread pools, cancellation strategies, and GUIs. This is also excellent. Part three covers performance and testing. The last 75 pages are for advanced users and goes into a fair amount of low level detail (including a discussion of the Java Memory Model), which may be of interest to experts only.
I would be lying if I said that reading this book will demystify concurrency completely. Who wrote which bit of the book is unclear (although readers of Effective Java will probably spot parts of the text that seem rather Joshua Blochish), but while it's mostly very clear, some parts of the text are a little murkier than other. Perhaps this is to be expected given the subject matter. But for the most part it's surprisingly easy reading, and very practical to boot.
Let's face it, short of aliens landing and introducing a radically new way of computing, multicores are here for the medium term at least, so thread-dodging wimps such as myself will just have to get used to it. That being so, this book is going to be installed as one of the must-read books in the Java pantheon.
The book stands on par with such established Java book jems as Josh Bloch's "Effective Java", Eckel's "Thinking in Java" and Rod Johnson's J2EE books.
All in all, this is a definite must have for any Java specialist.
Concurrency is perhaps one of the hardest issues to understand well and it's equally difficult to explain all of the issues, but Goetz et. al. do a very nice job of explaining clearly the different ways a multi-threaded process can fail and then providing concrete design philosophies that will help address those problems.
In my experience, concurrency books often fall between providing too little detail ("just add synchronized to everything and all should be well") to providing too much ("details of how the Java Memory Model actually behaves on a multi-processor machine"). Java Concurrency in Practice seems to find a nice balance, e.g. thoroughly explaining why you need to worry about how values are "published" between threads but without swamping you with so much information about the details of how this is done by the VM that you're left gasping for air.
For me, this is a focus on the practical aspects of building multi-threaded applications in real world situations. In such cases, you need to fully understand the potential pitfalls and then you want to have a list of specific design methodologies which help avoid those failings. Java Concurrency in Practice does a nice job of providing both.
This is clearly one of the top notch Java books like Doug Lea's original "Concurrent Programming in Java". And like CPIJ it is scary. Can one ever get the concurrency aspects right enough? Are the books of other authors trustworthy (enough)? There is so little help from the language itself and the IDEs to get things concurrency correct. And the authors show in many examples, what all can go wrong and that our old "Von Neumann machine" intuition is plainly wrong and often highly misleading. With the inevitable concurrency, Java is in fact a language for advanced programmers. Things will in practice get worse due to the increasing ubiquity of multiprocessor computers even on the desktop.
The book is written by leading Java experts. It cites and uses in an unusually extensive ways some of the other classics in our Java world:
Arnold et al. "The Java Programming Language",
Lea "Concurrent Programming in Java",
Gosling et al. "Java Language Specification" and
Bloch "Effective Java".
It is helpful but not mandatory to know them. Better it is to have them handy to be able to quickly look things up. Most other referenced works are original articles.
"Java Concurrency in Practice" is written in a readable style - though the material is presented in an unusual dense way for an Addison and Wesley Java book. Expect an information density more like an O'Reilly one, but a lot lower than a Springer one. Anyhow the book gets easier to read as you and your understanding progresses.
The presented material relies on and explains the new concurrency features of Java 5 and even Java 6. But it is not a tutorial of the new concurrency classes. It is a high level introduction from the usage pattern point of view. It explains the new classes only as far as is necessary.
One of my favorite chapters is on testing concurrent programs. Yes, it is possible to make unit tests for concurrent classes. No, it does not look like it is much fun though. But, you get a good head start. Besides peer review you also find some testing help in static analyzers like "findbugs".
In summary I recommend this book as one of the core Java books. I still wish the world is - with respect to multithreading - easier and less intimidating.
Each section has a solid example that will also stand up in the real world.
The book was put together very carefully, with great attention to detail, as is essential for a book about concurrency.
One of the best parts of the book was Brian leading me on all the time. He would show me a piece of code as a solution to a problem, and I would think of ways that it could cause problems. He then addressed those problems on his next page, but caused other problems. This carried on until the final solution, which was always elegant beyond anything I have written :-)
A solid 5 star rating for this book!
Definitely a good meaty book for Java Specialists.
I take the chance to publicly thank all the authors for sharing their knowledge with an excellent, clear and concise style.
The book chooses a very thoughtful level of abstraction which gives the reader the opportunity to absorb the essential problems and patterns without straying too far from the inconvenient realities, at the same time teaching a kind of framework for analysis of multithreading issues. It is a very well organized book that will serve as a fine reference after providing the initial learning experience. The book's focus on the Java 5 concurrency library makes both the lessons and the library accessible and easy to exploit. The lessons are deep and varied and without exception practical.
Practising multithreaded programming in Java without reading this book is like doing aerials without a net. If you choose not to read it, good luck, and I hope it doesn't hurt too much.
Included is a discussion of GUI development considerations, performance considerations, and testing strategies. Within an advanced topics section the authors cover explicit locks, custom synchronizers, and the Java memory model with respect to concurrency issues.
The writing style is clear, concise, and readable. Well worth the investment for the beginner or advanced student and sure to be referred to again and again in the future.
I come from the embedded system realm where most of what Mr Goetz talks about, at least in theory, is second nature. However in Java, second nature for c/c++ doesn't mean you know how to do the same things in Java. Mr Goetz will get you there. From locking, to local copies, to shared spaces to Java specific executors - Mr Goetz covers it all. What I particularly enjoyed was his section on performance. Too often, when writing concurrent code, one tends to over protect. In Java Concurrency we are taught how to gain performance and still be safe. To say that the concept of scaling was well covered would be an understatement.
Quite frankly, this is one of the best programming books I've ever read. Up there with Code Complete. It will change the way you think about programming - for the better.
I buy this book for everyone who starts on my team. It is really that good.
Of course, JCP talks about the Java 5 concurrency library at great length. But this is no paraphrasing of the javadoc. (It was Doug Lea's original concurrency utility library that eventually got incorporated into Java, and we're all better off for it.) The authors start with illustrations of real issues in concurrent programming. Before they introduce the concurrency utilities, they explain a problem and illustrate potential solutions. (Usually involving at least one naive "solution" that has serious flaws.) Once they show us some avenues to explore, they introduce some neatly-packaged, well-tested utility class that either solves the problem or makes a solution possible. This removes the utility classes from the realm of "inscrutable magic" and presents them as "something difficult that you don't have to write."
The best part about JCP, though, is the combination of thoroughness and clarity with which it presents a very difficult subject. For example, I always understood about the need to avoid concurrent modification of mutable state. But, thanks to this book, I also see why you have to synchronize getters, not just setters. (Even though assignment to an integer is guaranteed to happen atomically, that isn't enough to guarantee that the change is visible to other threads. The only way to guarantee ordering is by crossing a synchronization barrier on the same lock.)
I've seen hundreds of web site crashes. Every single one of them eventually boils down to blocked threads somewhere. Java Concurrency in Practice has the theory, practice, and tools that you can apply to avoid deadlocks, live locks, corrupted state, and a host of other problems that lurk in the most innocuous-looking code.
The book teaches you more than just the theoretical aspects of concurrent programming such as exclusion mechanisms, liveness and safety issues, it shows the correct way to do it in Java.
A comprehensive tutorial of the concurrency package provided in j2se 5 and 6 is given, and I think it is a crucial aid for writing correct and maintainable concurrent code in Java.
The advanced topics in the book give you a better understanding of the inner workings of Java and even the inner workings of compilers and modern processors and this is done without going into redundant details.
The only comment I have about the book, is that I would expect at least a chapter or two about parallel and distributed programming and the available Java frameworks that support it.
I would highly recommend this book to any Java programmer, as you are probably missing out on part of the capabilities of your language (and/or writing incorrect programs!) until you read this. It's probably not a bad lesson for developers of concurrent software in any language, but the concrete instructions regarding Java were really the most valuable part of the book to me.
If you work in java with threaded code, stop whatever you're doing and read this book, now!
This book goes way beyond the Sun documentation. It looks at many aspects of concurrency. Including how to make a thread safe class. Which is one of the basic things you need, given that Java is object oriented, and a typical program makes classes specific to its needs. Here, the guidelines are concise, requiring that you focus on defining the class's invariants and the variables that define the state of the class. The book does not seem to explicitly talk about the concept of a finite state machine. But that is essentially what you might want to consider for each of your classes that will have multithreaded access.
Also well worth attention is the chapter on multithread performance. Germane with the increasing availability of multicore processors. The chapter has a lucid explanation of the costs of having too many threads. You need to strive to minimise the maximum number of threads in your application. Context switching can be extremely costly in terms of time, and greatly reduce the overall efficiency.
Contents:
Introduction
I. Fundamentals: Thread Safety; Sharing Objects; Composing Objects; Building Blocks
II. Structuring Concurrent Applications: Task Execution; Cancellation and Shutdown; Applying Thread Pools; GUI Applications
III. Liveness, Performance, and Testing: Avoiding Liveness Hazards; Performance and Scalability; Testing Concurrent Programs
IV. Advanced Topics: Explicit Locks; Building Custom Synchronizers; Atomic Variables and Nonblocking Synchronization; The Java Memory Model; Annotations for Concurrency
Bibliography; Index
This book picks up from the regular documentation on how specific synchronization and threading features work. Goetz does a relatively light introduction to the topic, and then starts into practical issues that you'll encounter in real programs and applications. For instance, a specific component, such as a collection, might be thread-safe. But what happens if that component is part of a compound function you've written? The compound function may well have "features" that you don't expect when running in the wild, since the threading issues now have to be considered at a level higher than the specific component. And being that you rarely have a clue as to how your program will mix with others, a bad design can lead to nasty intermittent threading bugs that are nearly impossible to consistently recreate. Goetz goes beyond the "write your code this way" material to explain how both code *and* design have to work in concert with each other to make sure a multi-threaded application behaves the way it should.
I was also impressed with the number of examples, both good and bad. By having a large number of "don't do this" samples, it's likely you'll see something that might be common practice in your coding style (but that will need to be changed). He also summarizes the material in gray call-outs within the flow of the text, so you can quickly grasp the one or two line concept that needs to be remembered and internalized in practice.
In a single word, this book can be summed up as "practical". Everything is focused on how things really work, and how to avoid common practices that will lead to major trouble. This is a great addition to the Java shelf of my library, and I recommend it with no hesitation.
One thing though: to truly benefit from it I think you should have some experience in software design and coding multithreaded applications, and needless to say that you should feel comfortable with the Java standard library. for instance you will not understand the importance of client side locking or saturation and cancellation policies without proper experience in software design and multithreading.
The book covers almost everything you should know to write safe, high performance, efficient and scalable multithreaded applications, it drills down into most of the important classes in the Java concurrency library (java.util.concurrent), and explains how and when to use them. I love how the book is consistent with the previous Effective Java book (has many direct references to it) and how it puts emphasis on correctness and scalability. The book was written by my favorite Java gurus (Josh Bloch, Doug Lea), if you don't know these guys yet - you should. Bloch wrote most of the standard library, and Doug Lea's signature appears on most concurrency code in java.
Written for engineers, you can expect to also find benchmarking of different concurrent components, some formulas to measure and calculate optimal thread pool sizes, and many formal definitions and guidelines to live by.
Awesome. must have.
I started liking to read Brian Goetz and met him once at a No Fluff Just Stuff conference in Boston in 2010.
His articles online were very interesting and mind opening ones.
Same with this book. This book needs to be read slowly and digested and tried out before things make a lot of sense.
I was looking for a good concise book on Java Threading and Concurrency - after the overhaul was made in Java 5 onwards with the new Threading and Concurrency Libraries ( since reading disparate articles from the internet ) - made getting a conceptual clarity and full picture sometimes difficult.
This book solved my problem and filled the gap excellently.
I would recommend anyone working with Threads and needs to deal with Concurrency issues - to read this book.
With Multi core programming becoming the norm now - this book is a must read for any serious Java Developer
Thanks Brian - for taking your time in explaining the difficult concept lucidly in this book
I was really impressed with the ExecutorService framework for fixed thread pools. I was asked to create a pooling mechanism simulating an application server that can be used for standalone testing. I originally created and managed the threads myself in an array, but this book gave me the information for making more use of the Java API in keeping the code clean. Using Callable instead of Runnable is great for getting results from your processes after they complete, and Future gives you a hook for cancellation/interruption.
There is a really interesting discussion on JVM shutdown. I have sometimes had processes that threw a Runtime exception but still held a database lock, causing deadlocks and contention later on. This recommends doing the final resource cleanup in the finally block of the "run" method. However, what if a "grid" monitoring process forces shutdown of my application? Would the Object's final() method insure that that my resource was cleaned up so that no lock is still held by the grid's JVM? The answer seems to be that the final method is less reliably called than the finally block, and that you should make your tasks "interruptable" by polling an unbounded queue or calling the thread's isInterrupted() method frequently. My questions aren't all answered on this, but I still have another 150 pages to go in the book.
Also, this book clarifies a lot of obscure semantic points in the threading classes (for example, the handling and "rethrowing" of interruptions) and open your eyes on subjects hidden in the specs that most developers will never read nor understand at all (like most thread visibility issues.)
With that foundation, the description of the Java 5's "util.concurrency" package is pretty solid; the book is not focused on the "how to use" (you can check the javadocs), but on the "why" of the several provided implementations, so you can deduce the "where" to apply them (the book's authors also participated in the design of those concurrency utilities.)
At risk of sounding repetitive, this book is a must read for any Java developer since most of them are currently involved directly or indirectly in MT programming (for example, inside a servlet environment.)
If you are afraid of concurrency as of some monster (as I was) then this book will open your eyes and gives you enough confidence to make correct concurrency programs.
However, this book is not for Java beginners. You need to have an intermediate understanding of Java and some general programming/software engineering concepts. Also, if you are just starting with concurrent programming, this book might be slightly challenging at the beginning. But you should be able to pick it up fairly quickly.
And if you are already a concurrency expert or have quite some understandings about concurrency in general, this book will still solve a lot of the myths out there and may inspire you to further research on some of the topics.
Overall, this is a definite buy if you want to do concurrent programming.
The use of negative examples is really what makes this book great.
Although certain parts are a real brain tease (with certain pages taking 20-30 minutes of examination to fully understand) you come out with deep understanding that is lasting.
Bravo!
The best part about the book is Mr Yuk an icon to denote really bad thread unsafe code examples and comparison to different implementations that are correct -you will see from the first day onwards the mistakes that you have been making in your existing code. Very practical; Good explanation, lots of sample code.
Close your eyes look no further and get this book -you will not regret it.
Concurrent programming is difficult and if you need to do it, you need this book.
If you need to know about concurrency while developing for Java then look no further.
I will provide you with a concrete example:
On page 34, topmost paragraph, the authors state "and a thread other
than the publishing thread were to call assertSanity, it could throw AssertionError" then they elaborate but on the symptom: "The problem here is not the Holder class itself, but that the Holder is not properly published. However, Holder can be made immune toimproper publication by declaring the n field to be final, which would make Holder immutable;" rather than provide a concrete scenario of how the problem would occur. This leaves the reader trying to come up with a a sequence of events that will cause the AssertionError. In general, sometimes, after 30 mins or so, I would figure it out, but sometimes, as in this case, I can not.
On the other hand, the book does provide major practical benefits. For example, I had to refer to the book twice in one month, once to review the caching algorithm using FutureTask and one to trouble shoot a ConcurrentModificationException in JBoss from session replication. Hence, any book that I would need to refer to, however frequently or infrequently, deserves at least 3 stars. It would have been 4.5-5 stars if the explanations/justifications came with more detailed step-by-step replication procedure for all rather than for some. That could turn the book into a 500 page monster so I guess I understand why the authors didn't. Using the above example, I wished they had provided more scenarios of how/why ConcurrentModificationException is caused, in addition to the excellent example they provided (logger.info("...." + set) would generate the exception since set.toString() iterates thru the elements and other threads could be modifying the set).
I use it as a reference book.
The first time you read, its hard to follow. But i thought reading it once made me aware of what all things java had to offer and then later use it as a reference whenever I had to look into a topic again.
Create your own review



