Skip to content
క
kagitha
/
quiz
/
java-virtual-threads
Subscribe
Index
⌘K
JAVA NOTEBOOK · QUIZ 06 · INTERMEDIATE
Java 21 virtual threads
QUESTION 01 / 06
Before Java 21, what did every Java thread (a platform thread) map to?
A
One CPU core, reserved for that thread
B
One operating-system thread, for its whole life
C
A slot in a JVM pool shared by all threads
D
Nothing: the JVM scheduled threads on its own
SCORE SO FAR · 0 / 0
Share this quiz ↗
Before Java 21, what did every Java thread (a platform thread) map to?
— One operating-system thread, for its whole life. A platform thread is a thin wrapper around one OS thread. It is bound to that OS thread from start to finish and holds it even while it waits.
A Tomcat server has 200 threads. Each request does 5 ms of work and waits 100 ms on the database. What usually limits throughput?
— The number of threads, because waiting threads still hold their OS threads. The CPU sits mostly idle. All 200 threads are blocked waiting, so request 201 has to queue even though nobody is doing real work.
A virtual thread calls a JDBC query and has to wait. What happens to its carrier thread?
— The virtual thread unmounts, and the carrier runs another virtual thread. The virtual thread's stack is saved on the heap and it steps off the carrier. The carrier's OS thread immediately runs other work. When the result arrives, the virtual thread is mounted again and carries on.
Your service resizes images, keeping every CPU core at 100%. Will switching to virtual threads make it faster?
— No, virtual threads help with tasks that wait, not tasks that compute. Virtual threads make waiting cheap. CPU-bound work still needs a core the whole time, and you have the same number of cores as before.
On Java 21, a virtual thread blocks on I/O inside a synchronized block. What is the risk?
— It gets pinned to its carrier, blocking the carrier's OS thread. In Java 21 a virtual thread can't unmount while inside synchronized code, so it pins its carrier. Use ReentrantLock around blocking calls instead (Java 24 removed this limitation).
You want at most 20 calls at a time to a fragile partner API, using virtual threads. What should you use?
— A Semaphore with 20 permits. Don't pool virtual threads. Create one per task and use a Semaphore to cap how many can call the partner at once.
kagitha
Close
✕
Search everything — articles, videos, chapters, agents, books
01
AI
02
Java
03
System Design
04
Series
05
Manga
06
The Lab
07
Videos
08
Quizzes
09
Books
10
Resume