Quick revision
The short answer
The classic dumps from jstack and jcmd Thread.print list platform threads, including the carrier threads that run virtual threads, but not the many virtual threads that are waiting unmounted. To see those we use jcmd <pid> Thread.dump_to_file, in plain text or with -format=json, which includes virtual threads grouped by the container that created them, such as an executor or a structured task scope. Reading changes too: dumps can hold many thousands of threads, so we group identical stacks, focus on what the virtual threads wait for rather than how many exist, and use JFR events such as jdk.VirtualThreadPinned for pinning problems.
What to remember
In this answer, we saw that virtual threads run mounted on a few carrier threads and spend most of their time unmounted, which is why jstack and Thread.print show the carriers but not the waiting virtual threads. We used jcmd Thread.dump_to_file, in text or JSON, to dump every thread grouped by its container, grouped thousands of threads by stack to find the resource they wait for, moved from counting threads to measuring waits, and used the JFR event jdk.VirtualThreadPinned to find pinning.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The classic dumps from jstack and jcmd Thread.print list platform threads, including the carrier threads that run virtual threads, but not the many virtual threads that are waiting unmounted. To see those we use jcmd <pid> Thread.dump_to_file, in plain text or with -format=json, which includes virtual threads grouped by the container that created them, such as an executor or a structured task scope. Reading changes too: dumps can hold many thousands of threads, so we group identical stacks, focus on what the virtual threads wait for rather than how many exist, and use JFR events such as jdk.VirtualThreadPinned for pinning problems.
Why this question is asked
Virtual threads, final since Java 21, let a service run one cheap thread per request, so a busy application may have 50,000 threads instead of 200. That breaks some long-standing habits. The tool we reach for during every hang may not show most of those threads, and the rule of thumb 'all 200 threads are busy, so we are saturated' no longer means anything. Interviewers ask this to see whether we have actually debugged a virtual-thread application. In this answer, we will recap how virtual threads run on carriers, see what the old dump shows and misses, take the new kind of dump, and learn how to read a dump with thousands of entries.
1A Quick Recap: Virtual Threads and Carriers
A platform thread is the classic java.lang.Thread, a thin wrapper around an operating system thread. A virtual thread is also a java.lang.Thread, but the JVM manages it itself. When a virtual thread has work to do, the JVM mounts it on a carrier thread, a platform thread from a small ForkJoinPool that by default has as many threads as there are CPU cores. When the virtual thread blocks, for example on a socket read or a lock, the JVM unmounts it: its stack is saved on the heap and the carrier is free to run another virtual thread.
So at any moment only a handful of virtual threads are mounted and running, and all the others are just stack objects in memory, waiting. This is what makes them cheap, and it is also why the classic tooling sees them differently.
- Virtual threads, for example 40,000most unmounted, stacks stored on the heap
- Scheduler: a ForkJoinPoolmounts a runnable virtual thread on a free carrier
- Carrier threads, for example 8platform threads named
ForkJoinPool-1-worker-N - Operating system threadsone per platform thread
4 layers, from the top down. Step through them one at a time.
2What the Classic Thread Dump Shows
jstack and jcmd Thread.print walk the JVM's list of platform threads. In a virtual-thread application we see the carriers, the JVM's own threads, the GC threads and any platform pools we still use. The waiting virtual threads, which are exactly the ones we usually care about during a latency incident, are not there. A dump that looks almost empty while the service is stuck is a sign we are looking with the wrong tool.
3Taking a Dump That Includes Virtual Threads
The Thread.dump_to_file command, added with virtual threads, writes a dump of all threads, virtual ones included, to a file on the target machine. The default plain-text format is easy to read for small dumps. The JSON format is meant for tools: it lists threads inside thread containers, the objects that own them. Threads started by an ExecutorService from Executors.newVirtualThreadPerTaskExecutor() appear under that executor, threads forked inside a StructuredTaskScope appear under that scope, and threads started directly appear under the root container.
Notice two things. Virtual threads usually have no name, so we cannot identify them by name the way we identify http-nio-8080-exec-12; the stack and the container are our clues, and naming threads through Thread.ofVirtual().name(prefix, start) helps where we create them ourselves. Second, the container tells us which part of the application owns the threads, which is the virtual-thread replacement for 'which pool is full'. Recent JDKs have added more detail, such as thread state and lock information, to this dump; check your version for what it includes.
4Reading a Dump With Thousands of Threads
Nobody reads 38,000 stacks one by one. The useful step is to group threads by their stack and count each group. A few lines of jq or a small script turn the dump into a table such as: 31,800 threads parked in HikariPool.getConnection, 5,900 in a socket read inside the payment client, 500 in other places. That table is the diagnosis.
The second change is what we measure. With platform threads, 200 out of 200 busy request threads meant saturation. With virtual threads, the thread count simply grows with the load, so a high count says nothing. What matters is what the threads wait for. If 31,800 are waiting for a database connection, the database pool, sized at perhaps 50, is the real limit, and virtual threads have only moved the queue from Tomcat's accept queue into Hikari. That is a common surprise after migrating: virtual threads remove the thread limit, so the next limit, usually a connection pool or a downstream rate limit, becomes visible.
- Take Thread.dump_to_file -format=jsonseveral, seconds apart
- Group threads by top stack framescount each group
- Find the largest waiting groupswhat resource are they waiting for?
- Waiting on a pool or a downstream service?YesSize, timeout or shed load for that resourceNoCheck for pinning and CPU
4 steps in order. Play them, or step through them one at a time.
5Finding Pinning With JFR
Pinning is the case where a virtual thread blocks but cannot unmount, so it holds its carrier while it waits. In Java 21 to 23 this happened when a virtual thread blocked inside a synchronized block, which could starve a service with only eight carriers. JEP 491 in Java 24 removed that cause for most code, but pinning can still happen, for example when blocking inside a native method or a foreign function call.
A pinned virtual thread does show up on a carrier in the classic dump, so a dump in which every carrier sits in the same blocking call is a strong hint. The direct tool is Java Flight Recorder: the jdk.VirtualThreadPinned event is recorded, with a stack trace, whenever a virtual thread stays pinned while parking longer than a threshold (20 ms by default).
6Follow-up questions
Can I get a virtual-thread dump without jcmd, for example from inside the application?
Yes. The HotSpotDiagnosticMXBean, from com.sun.management, has a dumpThreads method that writes the same text or JSON dump to a file, so an application can expose it through an admin endpoint or call it when a watchdog fires. Spring Boot's actuator threaddump endpoint uses the classic thread API, so check your version for whether it includes virtual threads.
Why do virtual threads usually have no name in the dump?
Threads created by the virtual-thread-per-task executor and by many frameworks are unnamed by default, because naming millions of short-lived threads has a cost and rarely helps. Where we create them ourselves we can use Thread.ofVirtual().name("order-", 0).factory() to get numbered names, and we can always identify them by their container and stack.
Does the thread count still mean anything with virtual threads?
Only as a measure of concurrency, how many requests are in flight. It is no longer a saturation signal, because the JVM does not run out of virtual threads the way a 200-thread pool runs out. Saturation now shows as long waits on a shared resource, so we monitor pool wait times, pending connection counts and downstream latency instead.
7Conclusion
In this answer, we saw that virtual threads run mounted on a few carrier threads and spend most of their time unmounted, which is why jstack and Thread.print show the carriers but not the waiting virtual threads. We used jcmd Thread.dump_to_file, in text or JSON, to dump every thread grouped by its container, grouped thousands of threads by stack to find the resource they wait for, moved from counting threads to measuring waits, and used the JFR event jdk.VirtualThreadPinned to find pinning.
Open with
With virtual threads, the classic jstack or jcmd Thread.print dump only lists platform threads. I see the carrier threads of the ForkJoinPool and the JVM's own threads, but not the thousands of virtual threads that are unmounted and waiting, which are usually the interesting ones.
Then, if they want more
So I use jcmd pid Thread.dump_to_file, in plain text or with -format=json. The JSON dump includes virtual threads and groups them by thread container, so threads from a virtual-thread-per-task executor or a structured task scope appear under that owner.
The dumps can be huge, tens of thousands of threads, so I do not read them one by one; I group them by the top few stack frames and count, which quickly shows something like thirty thousand threads waiting in HikariPool.getConnection.
That also shows the main change in how I read them: the number of threads no longer indicates saturation, because it just grows with load. What matters is what they are waiting on, typically a connection pool or a downstream service, which is now the real limit.
For pinning, where a virtual thread blocks without releasing its carrier, I use JFR's jdk.VirtualThreadPinned event, which records a stack when a pinned park lasts over a threshold. Java 24 removed pinning on synchronized for most code, but it can still happen with native calls.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 24
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- java.util.concurrent, package documentation, JLS chapter 17, Threads and Locks
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do thread dumps work for applications using virtual threads, and what changes in how...": https://scrivio-interview-library.netlify.app/java/concurrency-problems/34194834d7/