Hi, I'm Ayan Dutta, a Software Architect, Instructor, and Content Creator.
I create practical, hands-on courses on Java, Spring Boot, Debugging, Git, Python, and more.
- 💬 Slack Group: Join Here
- 📢 After joining, go to the #java-virtual-threads-and-structured-concurrency channel
- 📧 Email: j2eeexpert2015@gmail.com
- 🔗 YouTube: LearningFromExperience
- 📝 Medium Blog: @mrayandutta
- 💼 LinkedIn: Ayan Dutta
![]() Eclipse Debugging Techniques |
![]() Java Debugging With IntelliJ |
![]() Java Debugging with VS Code |
![]() IntelliJ IDEA Tips & Tricks |
![]() Creational Design Patterns |
![]() Python Debugging With PyCharm |
![]() Python Debugging with VS Code |
![]() Python Debugging (Free) |
![]() GitHub Desktop Guide |
![]() Git & GitHub with Eclipse |
This repository contains all the demo code for the Udemy course: Java Virtual Threads & Structured Concurrency w/ Spring Boot
- JDK 21+ (stable virtual threads)
- JDK 19/20 also supported with
--enable-preview - IntelliJ IDEA or Eclipse (recommended)
- Maven 3.9+ for building projects
Clone the repository and navigate to the project directory:
git clone https://github.com/j2eeexpert2015/virtual-threads-structured-concurrency.git
cd virtual-threads-structured-concurrencyBuild the project:
mvn clean compileAdd --add-exports (and preview where needed) at compile and runtime.
Go to Settings → Build, Execution, Deployment → Compiler → Java Compiler → "Additional command line parameters":
--enable-preview --add-exports=java.base/jdk.internal.vm=ALL-UNNAMED
Go to Run/Debug Configurations → your app → VM options:
--enable-preview --add-exports=java.base/jdk.internal.vm=ALL-UNNAMED
You should already have set:
- Project SDK = Java 21
- Language level = 21 (Preview) for both Project and Modules
Keep these settings as they are.
After completing the setup above, you can run any demo directly from IntelliJ.
Run Basic Virtual Thread Demo:
mvn clean compile exec:java -Dexec.mainClass="com.example.virtualthreadcreation.BasicVirtualThreadCreation"Run Virtual Thread Builder Demo:
mvn exec:java -Dexec.mainClass="com.example.virtualthreadcreation.VirtualThreadCreationWithBuilder"Run Structured Concurrency Demo:
mvn exec:java -Dexec.mainClass="com.example.structuredconcurrency.ProductPageWithStructuredConcurrency"Run Continuation Demo:
mvn exec:java -Dexec.mainClass="com.example.continuation.SimpleContinuationDemo" -Dexec.args="--add-exports java.base/jdk.internal.vm=ALL-UNNAMED --enable-preview"For debugging jdk.internal.vm.Continuation and other internal APIs:
- Go to Run/Debug Configurations
- Click Modify options
- Select Add additional command line parameters
- Add the same VM options:
--add-exports java.base/jdk.internal.vm=ALL-UNNAMED --enable-preview
This enables the IntelliJ debugger to step into Continuation methods and other internal JDK classes.
src/main/java/com/example/
├── virtualthreadcreation/ # Basic virtual thread creation examples
├── structuredconcurrency/ # Structured concurrency demonstrations
├── scopedvalue/ # ScopedValue vs ThreadLocal examples
├── continuation/ # Low-level Continuation API examples
├── pinning/ # Virtual thread pinning detection
├── mountandunmount/ # Thread mounting behavior
└── util/ # Utility classes (JFR, profiling, etc.)
BasicVirtualThreadCreation.java- Simple VT creation patternsVirtualThreadCreationWithBuilder.java- Builder API usageVirtualThreadCreationWithThreadFactory.java- Factory patterns
ProductPageWithStructuredConcurrency.java- Real-world scenariosProductAvailabilityWithShutdownOnSuccess.java- Success patternsStructuredVsUnstructuredDemo.java- Side-by-side comparison
ScopedValueExample.java- Modern context handlingThreadLocalInheritanceProblem.java- Legacy issues demonstration
VirtualThreadMountUnmount.java- Mount/unmount behaviorVirtualThreadPinning.java- Pinning detection and preventionMillionVirtualThreads.java- Scalability demonstrations
JDK Version Compatibility:
--enable-previewis only required for JDK 19/20- On JDK 21+, virtual threads are stable - you can omit
--enable-previewunless using other preview features- Structured Concurrency requires
--enable-previewon all JDK versions (still in preview as of JDK 21)
Internal API Access:
--add-exports java.base/jdk.internal.vm=ALL-UNNAMEDis required forContinuationexamples- This exports internal JDK APIs that are normally encapsulated by the module system
⚠️ Warning: Internal APIs can change without notice - use only for learning purposes
Issue: IllegalAccessError with Continuation examples
Solution: Ensure VM options include --add-exports java.base/jdk.internal.vm=ALL-UNNAMED
Issue: ClassNotFoundException for preview features
Solution: Add --enable-preview flag and ensure using compatible JDK version
Issue: Maven exec plugin not finding main class
Solution: Run mvn clean compile first to ensure classes are built
This repository is designed to complement the "Java Virtual Threads & Structured Concurrency w/ Spring Boot" Udemy course. Each demo corresponds to specific course sections and lectures for hands-on learning.
For production Spring Boot examples with monitoring and observability, check out the companion repository: sample-retail-app
Happy Learning! 🚀










