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

#Java
#Concurrency
👋 به دنیای آینده جاوا خوش آمدید. با این کتاب، وارد فضای تحولآفرین یکی از کلیدیترین ویژگیهای جاوا ۲۱ میشوید: رشتههای مجازی (Virtual Threads).
📌 یادتان هست چقدر با هزینه سنگین ایجاد رشتهها دستوپنجه نرم میکردیم؟ یا محدودیتهایی که در مقیاسپذیری داشتیم و سختیهایی که برای رسیدن به توان پردازشی بالا تحمل میکردیم؟ آن دوران دیگر تمام شده است.
🚀 این راهنمای کاربردی، شما را از روزهای جاوا ۱.۰ تا پیشرفتهای پیشرو در پروژه لوم (Project Loom) همراهی میکند.
☕ شما در اینجا فقط تئوری یاد نمیگیرید. نویسنده کتاب، ای ان ام بازلور رحمان، شما را به ابزارهایی مجهز میکند که در پروژههای واقعی به کارتان میآید.
🛠️ قرار است عمیقاً وارد جزئیات پیچیده رشتههای مجازی و مباحث تخصصی مثل ForkJoinPool، Continuation، محدود کردن نرخ فراخوانی (Rate Limiting)، دیباگ کردن و مانیتورینگ شوید.
💡 نهتنها یاد میگیرید اینها چطور کار میکنند، بلکه نکات و ترفندهای حرفهای را برای تسلط بر این مفاهیم به دست میآورید.
✨ همچنین با ساختار همروندی (Structured Concurrency) و مقادیر محدود شده (Scoped Values) آشنا میشوید؛ مهارتهای حیاتی برای ساخت اپلیکیشنهای جاوایی که هم مقیاسپذیر باشند و هم بهینه.
🔍 درک عمیق و همهجانبه از رشتههای مجازی
🛠️ شناخت نحوه پیادهسازی داخلی رشتههای مجازی
🚀 کسب بهبود عملکرد در عملیاتهای مسدودکننده (Blocking)
💡 درک اینکه چرا ساختار همروندی سودمند است
📍 دانستن اینکه کجا باید از مقادیر محدود شده استفاده کرد
🔄 درک جایگاه برنامهنویسی ریاکتیو در حضور رشتههای مجازی
فهرست مطالب
۱. مقدمه
۲. درک رشتههای مجازی
۳. مکانیسمهای همروندی مدرن در جاوا
۴. ساختار همروندی
۵. مقادیر محدود شده
۶. جایگاه جاوا ریاکتیو با توجه به ظهور رشتههای مجازی
۷. فریمورکهای مدرنی که از رشتههای مجازی استفاده میکنند
۸. نتیجهگیری و دستاوردها
این کتاب برای چه کسانی است؟
💻 این کتاب برای آن دسته از توسعهدهندگان جاوایی طراحی شده که در حال حاضر درک پایهای از همروندی و چندرشتهای (Multithreading) دارند.
🚫 این یک راهنمای مقدماتی برای این مباحث نیست؛ بلکه هدفش متخصصانی است که تجربه نوشتن برنامههای همروند را با ابزارهای سنتی مثل Thread، ExecutorService، همگامسازی و ابزارهای مجموعهای مثل ReentrantLock و Semaphore دارند.
📈 هدف این است که دانش خود را درباره ویژگیهای مدرن همروندی (بهویژه رشتههای مجازی، ساختار همروندی و مقادیر محدود شده) عمیقتر کنید.
📚 اگر به دنبال یادگیری اصول پایه همروندی هستید، کتاب Java Concurrency in Practice اثر برایان گوتز همچنان گزینه پیشنهادی ماست.
🛠️ اگر تا به حال با چالشهایی مثل اتمام ظرفیت رشتهها، ورودی/خروجی مسدودکننده (Blocking I/O)، تنظیم دقیق استخر رشتهها یا مدیریت چرخهحیات روبرو شدهاید، این کتاب به شما کمک میکند.
این کتاب بهویژه برای این افراد مفید است:
👨💻 توسعهدهندگان سطح متوسط تا ارشد که قصد مدرنسازی کدهای خود را دارند
🏗️ معمارانی که سیستمهای مقیاسپذیر طراحی میکنند
⚡ مهندسان متمرکز بر عملکرد که به دنبال ساخت اپلیکیشنهای پایدار هستند
👥 سرپرستان تیم که در حال ارزیابی تکنولوژیهای جدید هستند
🤔 هر کسی که درباره آینده همروندی در جاوا کنجکاو است
📚 توسعهدهندگان جونیور که درک پایهای از جاوا دارند هم میتوانند برای مرور کلی همروندی مدرن از این کتاب استفاده کنند.
⚠️ با این حال، مطالعه قبلی یا همزمانِ مباحث پایهای مثل همگامسازی، شرایط رقابتی (Race Conditions) و انتشار دادهها برای درک کامل مطالب اکیداً توصیه میشود.
💎 این اصول برای نوشتن کد همروندِ موثر حیاتی هستند. اگرچه برخی فریمورکهای مدرن این جزئیات را مخفی میکنند، اما وقتی با یک باگ جدی روبرو میشوید، همین دانش پایه است که نجاتبخش خواهد بود.
این کتاب چه چیزی ارائه میدهد؟
📝 این کتاب هر آنچه که من درباره پروژه لوم و رشتههای مجازی آموختهام را در یک منبع جامع گردآوری کرده است. در داخل کتاب خواهید یافت:
📈 بررسی تکامل همروندی در جاوا؛ از رشتههای پلتفرم تا برنامهنویسی ریاکتیو
🔬 بررسی عمیق مکانیسمهای رشتههای مجازی، ساختار همروندی و مقادیر محدود شده
💻 مثالهای کاربردی و واقعی برای استفاده موثر از این ویژگیهای جدید
📚 پوشش گسترده نهتنها رشتههای مجازی، بلکه سایر ویژگیهای مرتبط
🌐 راهنمایی درباره نحوه یکپارچهسازی در فریمورکهایی مثل Spring Boot و Quarkus
✨ چه در دنیای رشتههای مجازی تازهوارد باشید و چه از ابتدای شروع پروژه لوم آن را دنبال کرده باشید، دانش کاربردی فراوانی در اینجا پیدا خواهید کرد.
⚠️ مثالها و مفاهیم این کتاب حداقل به JDK 21 نیاز دارند. با این حال، داشتن دسترسی به نسخههای جدیدتر مثل ۲۴ یا حتی ۲۵ به شما اجازه میدهد بیشترین بهره را از تمام مثالها ببرید.
درباره نویسنده
👤 ای ان ام بازلور رحمان یک مهندس نرمافزار با بیش از یک دهه تجربه تخصصی در جاوا است.
🎤 او به عنوان یک سخنران فعال در کنفرانسهای بینالمللی، اغلب بر موضوعات تخصصی مانند همروندی و رشتههای مجازی تمرکز دارد.
🏆 او یک 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.









