Grokking Java Interview Questions
0% completed
Virtual Threads and Structured Concurrency
A program on JDK 21 starts 10,000 threads, and each of them waits one second for a reply. For this run, the JVM was limited to 2 operating system threads for executing them. Its output contains two numbers:
replies: 10000 carriers used: 2
Each reply arrived, although 2 operating system threads served 10,000 Java threads. The answers below explain what such a thread is, how it runs, when it also blocks its operating system thread, and which work it does not suit. Virtual threads need Java 21, so their code is shown as listings
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%