DEV Community

Cover image for My thoughts on Java Concurrency in Practice
Preslav Mihaylov
Preslav Mihaylov

Posted on • Edited on • Originally published at pmihaylov.com

My thoughts on Java Concurrency in Practice

One of my key goals this year was to gain a good understanding of concurrency and multithreading. I've always had a tangent understanding of it at best. The book Java Concurrency in Practice was one of my first picks.

Sure, I've used multithreading concepts like promises & ajax in JavaScript before. I've also spawned go routines & used mutexes in Go. But I've never felt I'm proficient enough to state that I have a good understanding of this subject.

Hence, to bridge this gap in knowledge & skills, I decided to invest in several concurrency related books & courses. My intention was to start from JCIP and then move on to some additional courses. Initially, I felt that just reading this book won't be sufficient to understand the subject thoroughly.

However, after going through this book I didn't bother looking into any other concurrency course at all. It is one of the most succinct and yet thorough books on a given topic that I've ever read.

Additionally, I would recommend you to go through this book even if you're not using Java at all. It will give you a very profound understanding of whatever framework/mechanism your language of choice uses to tackle concurrency.

Here's why...

Completeness

Java Concurrency in Practice is very thorough as it takes you from the basics you need to understand about concurrent programs all the way to the advanced topics, where the "dessert" is.

However, it is also quite succinct as it doesn't drift into unnecessary details or complexities which aren't foundational to the subject.

Many books and courses fail to achieve this.

Some drift too much towards the theoretical and impractical. This makes the reader impatient and eventually, repels him from the book/course altogether. Most classical computer science books are like this, making them quite unattractive to novices and professionals alike.

Others skip the foundations and simply focus on showing you "how it's done in X", where X is your favourite language. This kind of content might, at best, leave you hungrier than you were at the beginning. Worst case scenario, it might fool you into believing that "you know it all" and not study the subject further.

There are very few courses & books which achieve the golden balance between theory and practice.

Accessibility

Many books tend to be written in a very high-level way, skipping appropriate examples and using inaccessible language/terminology.

These kinds of books require unnecessary additional attention in order to understand the context alone. This is quite deterring, especially when the reader realises that there are good alternative books on the subject half-way through.

I avoid investing too much time in such books as reading those often contributes solely to "ego-reading" - giving you the prestige of a person who has read a book, which is considered a hard read. Understanding it is, though, is not a given.

Now, I would consider Java Concurrency in Practice to be quite accessible and written in a very pedagogical way. It is full of examples to supplement the book & aid you in "getting it".

However, I wouldn't mark it as an easy read. It took me substantial effort to go through the book. I read through each chapter at least twice, while also taking notes along the way.

Critique

Lack of exercises

What the book unfortunately lacks is a set of good exercises.

That would have been tremendously helpful as it supplements the read-through with "getting your hands dirty".

This is why I had to tinker with the concepts in the IDE myself. This was the only way to back my theoretical understanding with enough practice.

Google doesn't have any good suggestions either. The top result which pops up after you search for "concurrency projects" suggests some quite impractical projects. Projects such as creating your own concurrent hash map or implementing an atomic variable.

I find this to be bad exercise advice as all these are concurrency primitives. Knowing how to implement them yourself is useless.

They are already available out of the box and the book goes into enough depth to explain how they work.

What's more, these exercises won't prepare you for an actual concurrency-related problem. Just because you know the concurrency primitives doesn't mean you can use them effectively.

It would have been great if there were a couple of exercises in addition to each chapter. This would aid one in putting the concepts covered to practice.

Although the book is lagging on this important point, fortunately it is still very well-made in all other aspects. Additionally, the provided examples help one bridge the gap even though you'll have to do some homework afterwards.

The book doesn't cover modern tools & frameworks

The other critique I've often encountered is that the book doesn't cover the most modern practices in tackling concurrency. One could expect this given the book's age.

However, I don't consider this to be that important. The book focuses on providing you with understanding of the fundamental concurrency concepts and problems.

After you go through it, learning about the latest concurrency framework is a breeze.

It is far more beneficial to understand the concepts covered in JCIP than it is to know the API of the latest framework.

How to approach this book

JCIP quite thoroughly covers the subject of concurrency and the author has also written it in an accessible way. However, this is not a "feel-good" book. It's not meant to be read from cover to cover. It is also not meant to be among the collection of 100 books you've read this year. It will definitely impede you in achieving that "paramount" goal.

I'd advise readers to go through most chapters multiple times, especially the first five ones. In addition to that, I'd suggest one to take notes and even spend some time in the IDE tinkering with the concepts learnt.

Have in mind that the author doesn't spend too much time explaining the APIs of the library routines they use. Don't be taken aback by this, simply keep a browser tab open, ready to look up the API documentation of the methods being used.

Now, I wouldn't recommend these measures with any book as it is quite the time investment. But it's definitely worth it for this one.

There are easier books & courses on the subject out there.

But almost all of them leave you with a "there's something missing" feeling. This makes you hop from one piece of content to another.

This contributes to that never ending feeling that you don't have a good enough understanding of concurrency.

Java Concurrency in Practice is not like that. It will leave you fulfilled & confident that you understand the subject. After going through it, you'd rarely want to look to another book/course on the subject.

But it does demand its share of attention and care. Don't pass on this opportunity, it is definitely worth it.

Prerequisites

Although JCIP is accessible, it still demands some backbone knowledge before starting it.

Make sure that you are comfortable with an object-oriented programming language. You should also be comfortable opening the official documentation of an API over a stack overflow question.

In addition to that, the book doesn't cover the very basics of multithreading.

Concepts such as what a thread is, how it works or how to start one up. Make sure you spend a couple of days/weeks studying that beforehand.

Conclusion

Java Concurrency in Practice is one of the best books I've read on concurrency. I would recommend it to anyone, even if Java is not their language of choice.

Its lack of exercises does force one to do some homework. But even so, the course makes most other content on concurrency obsolete.

Due to this, JCIP does demand considerable attention, despite it being accessible, but it's definitely worth it.

Top comments (2)

Collapse
 
bhavukgarg profile image
Bhavuk-Garg

Thank you, I was wondering if this book was the right choice

Collapse
 
pmihaylov profile image
Preslav Mihaylov

Thank you! I definitely think it's among the best books on the subject.

Most books don't cover thread-safety & concurrency issues in enough depth. This book goes to that length but without drifting too much into the parts which are too advanced and you don't need