Leanpub Header

Skip to main content

Concurrent Programming in Java

From Traditional Threads to Project Loom

Concurrent Programming in Java
This book is 100% completeLast updated on 2026-09-25

Master the ideas behind Java concurrency, from threads, race conditions, and synchronization to CompletableFuture, virtual threads, and structured concurrency. With practical patterns, runnable examples, and a companion GitHub repository, this book helps you move from understanding concurrency to applying it in real programs.

Minimum price

$9.99

$14.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

Concurrent programming is one of the most powerful parts of Java, but also one of the easiest to get wrong. This book provides a practical and progressive introduction to writing concurrent programs with modern Java.

Starting with traditional threads, shared state, race conditions, synchronization, and thread safety, the book builds toward higher-level abstractions including atomic operations, concurrent collections, executors, futures, CompletableFuture, virtual threads, and structured concurrency.

Along the way, you will explore common concurrency patterns and techniques such as producer-consumer pipelines, task coordination, asynchronous composition, resource limiting, and safe access to shared data. The emphasis is not only on learning APIs, but on understanding the problems they are designed to solve and the trade-offs involved in choosing between them.

Examples are kept focused and practical so that the behavior of concurrent programs can be observed and experimented with directly. The book also discusses typical concurrency problems, including race conditions, deadlocks, livelocks, starvation, and busy waiting.

A companion GitHub repository, referenced inside the book, contains runnable versions of the examples presented in the chapters, together with additional real-world examples that combine multiple concurrency mechanisms in complete applications.

Concurrent Programming in Java is intended for developers, students, and instructors who already understand basic Java and want to progress from traditional thread-based programming to the concurrency model introduced by Project Loom.

Author

About the Author

Florin Radu

Florin Radu graduated with an Engineering degree in Automation and Computer Science in 2007, earned his MSc in Systems Engineering in 2009, and completed his PhD in Systems Engineering in 2011. He has worked as a software engineer and consultant in the software industry for approximately 15 years. He has also been teaching at a technical university in Romania for 19 years, with a focus on software engineering, real-time systems and related computer engineering topics.

Contents

Table of Contents

  • 1. Introduction
    • 1.1. Why Concurrent Programming?
    • 1.2. What Does "Concurrency" Mean in Java?
    • 1.3. The Evolution of Concurrency Support in Java
    • 1.4. Goals of This Book
    • 1.5. Who Is This Book For?
  • 2. Concurrency Fundamentals
    • 2.1. What Is Concurrency?
    • 2.2. Concurrency vs. Parallelism
    • 2.3. Process vs. Thread
    • 2.4. Benefits of Concurrent Programming
    • 2.5. Challenges and Risks of Concurrent Programming
    • 2.6. Concurrency Models
    • 2.7. Conclusion
  • 3. Lambda Expressions and the Stream API
    • 3.1. From Anonymous Classes to Lambda Expressions
    • 3.2. Functional Interfaces
    • 3.3. Lambda Expressions and Captured Variables
    • 3.4. Method References and Equivalent Lambda Expressions
    • 3.5. Introduction to the Stream API
    • 3.6. Intermediate and Terminal Stream Operations
    • 3.7. Practical Stream API Examples
    • 3.8. Optional and Missing Values
    • 3.9. Parallel Streams
    • 3.10. Conclusion
  • 4. Threads in Java - The Traditional Model
    • 4.1. Introduction
    • 4.2. How Threads Execute
    • 4.3. Creating and Starting Threads
    • 4.4. Common Thread Methods
    • 4.5. Mutual Exclusion with synchronized
    • 4.6. Thread Cooperation with wait(), notify(), and notifyAll()
    • 4.7. volatile Variables - Visibility Between Threads
    • 4.8. Thread Scheduling
  • 5. Modern Concurrency Mechanisms in Java (java.util.concurrent)
    • 5.1. Introduction to java.util.concurrent
    • 5.2. Locks and Conditions
    • 5.3. Synchronization with Semaphores and Barriers
    • 5.4. Atomic Operations and Lock-Free Programming
    • 5.5. Concurrent Data Structures - Thread-Safe Collections
    • 5.6. Synchronizing Data Exchanges
    • 5.7. Executor Framework - Modern Thread Management
    • 5.8. CompletableFuture - Modern Asynchronous Programming in Java
    • 5.9. Best Practices for Using java.util.concurrent
    • 5.10. Conclusions
  • 6. Classic Problems in Concurrent Programming
    • 6.1. Race Conditions
    • 6.2. Deadlocks
    • 6.3. Livelock
    • 6.4. Thread Starvation
    • 6.5. Other Problems in Concurrent Programming
  • 7. Design Patterns for Concurrent Programming
    • 7.1. Coordination Patterns
    • 7.2. Execution Patterns
    • 7.3. Messaging Patterns
    • 7.4. Structural Patterns
    • 7.5. Conclusions
  • 8. Virtual Threads and Structured Concurrency (Project Loom)
    • 8.1. Introduction: The Shift Brought by Project Loom
    • 8.2. What Are Virtual Threads?
    • 8.3. Benefits and Limitations of Virtual Threads
    • 8.4. Creating Virtual Threads
    • 8.5. Structured Concurrency
  • 9. General Conclusions: Choosing the Right Tool for Modern Java Concurrency
    • 9.1. From Traditional Threads to Modern Concurrency
    • 9.2. There Is No Universal Mechanism
    • 9.3. When to Use Traditional Mechanisms
    • 9.4. When to Use Modern java.util.concurrent Tools
    • 9.5. When to Choose ExecutorService
    • 9.6. When to Choose CompletableFuture
    • 9.7. When to Choose Virtual Threads
    • 9.8. When to Choose Structured Concurrency
    • 9.9. A Practical Decision Rule
    • 9.10. Common Mistakes in Concurrent Applications
    • 9.11. Where Is Java Heading?
    • 9.12. Final Conclusion
  • References

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub