Virtual Threads, Structured Concurrency, and Beyond
A N M Bazlur Rahman

#Java
#Concurrency
🚀 به آینده Java خوش آمدید. با این کتاب، شما وارد دنیای تحولآفرین یکی از کلیدیترین قابلیتهای Java 21 میشید: تردهای مجازی (Virtual threads). چالشها و سردردهای قدیمی مثل هزینه بالای ساخت ترد، محدودیتهای اسکیلپذیری و دستوپنجه نرم کردن با رسیدن به Throughput بالا رو یادتونه؟ اون روزها دیگه تموم شده. این راهنمای کاربردی شما رو از جاوا ۱.۰ به پیشرفتهترین دستاوردهای پروژه لوم (Project Loom) میبره.
💻 شما تو این کتاب فقط تئوری یاد نمیگیرید. نویسنده کتاب، بانیور رحمان، شما رو با یک تولکیت کاملاً کاربردی برای پروژههای دنیای واقعی مجهز میکنه. یک Dive عمیق خواهید داشت به پیچیدگیهای تردهای مجازی و مباحث سنگینی مثل ForkJoinPool، کانتینیویشن (Continuation)، محدود کردن نرخ درخواست (Rate limiting)، دیباگ و مانیتورینگ. شما نه تنها یاد میگیرید این مفاهیم چطور کار میکنند، بلکه نکات و ترفندهای حرفهای رو برای مستر شدن تو اونا یاد میگیرید. علاوه بر این، با همزمانی ساختاریافته (Structured concurrency) و Scoped values آشنا میشید—که مهارتهایی حیاتی برای ساخت اپلیکیشنهای جاوا اسکیلپذیر و بهینه هستن.
⚙️ رسیدن به درک عمیق و جامع از تردهای مجازی (Virtual threads)
🧠 درک نحوه پیادهسازی و ساختار داخلی تردهای مجازی
⚡ بهبود چشمگیر پرفورمنس در عملیاتهای بلاکینگ (Blocking operations)
🔄 یادگیری اینکه چرا همزمانی ساختاریافته (Structured concurrency) اینقدر کاربردی و مفیده
📍 شناخت دقیق جاهایی که باید از Scoped value استفاده کرد
🤖 درک جایگاه جاوای رایکتیو (Reactive Java) با ظهور تردهای مجازی
فصل ۱. مقدمه
فصل ۲. درک تردهای مجازی
فصل ۳. مکانیسم همزمانی مدرن در جاوا
فصل ۴. همزمانی ساختاریافته
فصل ۵. مقادیر اسکوپشده (Scoped Values)
فصل ۶. جایگاه جاوای رایکتیو در حضور تردهای مجازی
فصل ۷. فریمورکهای مدرن بهرهمند از تردهای مجازی
فصل ۸. نتیجهگیری و دستاوردها
🎯 این کتاب برای Java developerهایی دیزاین شده که از قبل یک درک پایهای و قوی از مفاهیم همزمانی (Concurrency) و مالتیثردینگ (Multithreading) دارن. این اثر اصلاً یک راهنمای مقدماتی برای این موضوعات نیست؛ بلکه دقیقاً کسانی رو تارگت قرار داده که تجربه نوشتن برنامههای همزمان با ابزارهای سنتی مثل Thread، ExecutorService، سینکرونیزاسیون و ابزارهای کالکشن مثل ReentrantLock و Semaphore رو دارن و حالا میخوان درک خودشون رو از قابلیتهای مدرن همزمانی در نسخههای جدید جاوا—بهویژه تردهای مجازی، همزمانی ساختاریافته و مقادیر اسکوپشده—عمیقتر کنن. اگه میخواد پایههای همزمانی رو یاد بگیرید، کتاب Java Concurrency in Practice اثر برایان گوتز هنوز هم بهترین گزینه پیشنهادیه.
⚠️ اگه تا حالا با چالشهایی مثل اتمام ظرفیت تردها (Thread exhaustion)، بلاک شدن I/O، تیون کردن تردپولها یا مدیریت لایفسایکل و منطق کنسل کردن پروسسهای پیچیده دستوپنجه نرم کردید، این کتاب بهتون کمک میکنه با نگاهی نو و با توجه به مدل همزمانی در حال تکامل جاوا به این مسائل نگاه کنید. این کتاب به طور خاص برای این افراد مفیده:
💡 دولوپرهای جونیور هم که یک درک پایهای از جاوا دارن میتونن از این کتاب برای گرفتن یک اورویو کلی از همزمانی مدرن استفاده کنن. با این حال، مطالعه قبلی یا همزمان موضوعات پایهای مثل سینکرونیزاسیون، شرایط مسابقه (Race conditions) و نحوه انتشار داتا برای درک کامل کتاب کاملاً توصیه میشه. این پایهها برای نوشتن کدهای همزمان بهینه توی اپلیکیشنهاتون حیاتی هستن. در حالی که بعضی فریمورکهای مدرن این جزئیات رو از چشم دولوپرها پنهان میکنند، ولی وقتی با یک باگ جدی تو محیط پروداکشن روبهرو بشید، همهچیز حیاتی میشه. دانش پایهای همیشه برای فهم موضوع واجبه و همزمانی هم از این قاعده مستثنی نیست.
📚 این کتاب تمام چیزهایی رو که من درباره پروژه لوم و تردهای مجازی یاد گرفتم رو در یک منبع جامع جمعآوری کرده. در داخل کتاب پیدا خواهید کرد:
CompletableFuture و برنامهنویسی رایکتیو🏁 چه تازه با تردهای مجازی آشنا شده باشید و چه پروژه لوم رو از همان مراحل ابتدایی دنبال کرده باشید، این کتاب بینشهای ارزشمند و دانش عملی زیادی رو بهتون میده. مثالها و مفاهیم این کتاب حداقل به JDK 21 نیاز دارن، چون تردهای مجازی از این نسخه رسماً در دسترس قرار گرفتن. با این حال، برخی چپترها قابلیتهایی رو بررسی میکنند که هنوز در حالت پریویو هستن یا به تازگی نهایی شدن؛ بنابراین داشتن دسترسی به نسخههای جدیدتر JDK مثل ۲۴ یا حتی ۲۵ بهتون کمک میکنه بیشترین بهره رو از تمام مثالها و بحثها ببرید.
👨💻 ای ان ام بانیور رحمان یک مهندس نرمافزار با بیش از یک دهه تجربه تخصصی در Java و تکنولوژیهای وابسته به اونه. اون یک سخنران فعال در کنفرانسهای بینالمللی و گروههای کاربری جاواست و ارائههاش اغلب روی موضوعات تخصصی مثل همزمانی و تردهای مجازی تمرکز داشته. اون عنوان افتخاری Java Champion رو داره و ادیتور بخش Java Queue در رسانههای InfoQ و Foojay.io هست. اون همچنین بنیانگذار و مودریتور فعلی گروه کاربری جاوا در بنگلادش هست که از سال ۲۰۱۳ میتآپها و کنفرانسهای آموزشی مختلفی رو سازماندهی کرده.
Welcome to the future of Java. With this book, you'll explore the transformative world of Java 21's key feature: virtual threads. Remember struggling with the cost of thread creation, encountering limitations on scalability, and facing difficulties in achieving high throughput? Those days are over. This practical guide takes you from Java 1.0 to the cutting-edge advancements of Project Loom.
You'll learn more than just theory. Author A N M Bazlur Rahman equips you with a toolkit for taking real-world action. Take a deep dive into the intricacies of virtual threads and complex topics such as ForkJoinPool, continuation, rate limiting, debugging, and monitoring. You'll not only learn how they work, but you'll also pick up expert tips and tricks to help you master these concepts. And you'll learn about structured concurrency and scoped values—critical skills for building Java applications that are scalable and efficient.
Table of Contents
Chapter 1. Introduction
Chapter 2. Understanding Virtual Threads
Chapter 3. The Mechanics of Modern Concurrency in Java
Chapter 4. Structured Concurrency
Chapter 5. Scoped Values
Chapter 6. The Relevance of Reactive Java in Light of Virtual Threads
Chapter 7. Modern Frameworks Utilizing Virtual Threads
Chapter 8. Conclusion and Takeaways
Who This Book Is For
This book is designed for Java developers who already possess a foundational understanding of concurrency and multithreading. It is not a beginner’s guide to these topics. Instead, it targets those who have experience writing concurrent programs using traditional tools, such as Thread, ExecutorService, synchronization, and collection utilities like ReentrantLock and Semaphore, and are looking to deepen their understanding of the modern concurrency features introduced in recent Java releases, particularly virtual threads, structured concurrency, and scoped values. If you’re looking to learn the fundamentals of concurrency, Java Concurrency in Practice by Brian Goetz (Addison-Wesley Professional) is still the recommended book.
If you’ve ever encountered challenges with thread exhaustion, blocking I/O, thread pool tuning, or managing complex lifecycle and cancellation logic, this book will help you rethink these issues in light of Java’s evolving concurrency model. It is particularly beneficial for:
Junior developers with a basic understanding of Java will also find this book useful for an overview of modern concurrency. However, a prior or concurrent study of foundational topics such as synchronization, race conditions, and data publishing is highly recommended for a complete understanding. These fundamentals are vital for effectively writing concurrent code in your applications. While some modern frameworks hide these details from everyday developers, things become critical when encountering a serious bug. Fundamental knowledge is always essential for understanding the subject, and concurrency is no exception.
What This Book Offers
This book consolidates everything I’ve learned about Project Loom and virtual threads into one comprehensive resource. Inside, you will find:
Whether you are new to virtual threads or have been following Project Loom from its inception, you will discover valuable insights and practical knowledge.
The examples and concepts in this book require at least JDK 21, as that is when virtual threads became officially available. However, some chapters discuss features that are still in preview or have been recently finalized. Therefore, having access to a newer JDK version, such as 24 or even 25, will enable you to make the most of all the examples and discussions.
A N M Bazlur Rahman is a Software Engineer with over a decade of specialized experience in Java and related technologies. An active speaker at various international conferences and Java user groups, his talks have often focused on specialized topics such as concurrency and virtual threads. He is a Java Champion and an editor for Java Queue at InfoQ and Foojay.io. He is the founder and current moderator of the Java User Group in Bangladesh, where he has organized educational meetups and conferences since 2013.









