Monitoring Java Virtual Threads With JFR: Pinning, Lifecycle and Submit-Failed Events
How to observe virtual threads with JDK Flight Recorder: the jdk.VirtualThreadPinned event with its pinned reason, lifecycle and submit-failed events, recording from the command line or jcmd, reading results with jfr view and jfr print, and streaming events in-process with RecordingStream.
kvi5hnuCode Sprout team member6 min readOn this page
Earlier articles explained when virtual threads pin and when they hold their carriers. In a real application you don't find those places by reading every line of every library. You measure. The main tool is JDK Flight Recorder (JFR), the low-overhead event recorder built into the JVM. It's safe to keep on in production, and it records specific events for virtual threads.
The virtual-thread events
| Event | Enabled by default | What it records |
|---|---|---|
jdk.VirtualThreadPinned | yes, threshold 20 ms | a virtual thread blocked while pinned for longer than the threshold, with its stack trace and, since Java 24, the reason |
jdk.VirtualThreadSubmitFailed | yes | the scheduler failed to start or resume a virtual thread, usually a sign of resource exhaustion |
jdk.VirtualThreadStart | no | a virtual thread started |
jdk.VirtualThreadEnd | no | a virtual thread ended |
Start and end are off by default for a good reason: an application that creates a million virtual threads would record two million events. Turn them on for a short diagnostic run, not for every production recording.

Recording from the command line
Start a recording when the JVM starts:
java -XX:StartFlightRecording:filename=recording.jfr MyApp
The default settings already include the pinning and submit-failed events. To add the lifecycle events, override their settings in the same option:
java '-XX:StartFlightRecording:filename=recording.jfr,jdk.VirtualThreadStart#enabled=true,jdk.VirtualThreadEnd#enabled=true' MyApp
For a reusable configuration, the jfr configure command writes a settings file (.jfc) based on the defaults plus your changes, which you then pass with settings=:
jfr configure jdk.VirtualThreadStart#enabled=true jdk.VirtualThreadEnd#enabled=true --output vthreads.jfc
java -XX:StartFlightRecording:filename=recording.jfr,settings=vthreads.jfc MyApp
For an application that's already running, use jcmd with its process ID (from jps or jcmd without arguments):
jcmd <pid> JFR.start name=vt duration=2m filename=recording.jfr
jcmd <pid> JFR.dump name=vt filename=now.jfr # write what's recorded so far
jcmd <pid> JFR.stop name=vt
Reading a recording
The jfr tool in the JDK's bin folder reads .jfr files. Three commands cover most needs:
jfr view pinned-threads recording.jfr # a table grouped by the method where pinning happened
jfr summary recording.jfr # counts of every event type
jfr print --events jdk.VirtualThreadPinned recording.jfr # every event with all fields and stack
For the program in the next section, jfr view pinned-threads produced:
Pinned Virtual Threads
Method Pinned Count Longest Pinning Total Time Pinned
-------------------------------- ------------ --------------- -----------------
Solution.pause(long) 1 125 ms 125 ms
and jfr print showed the full event:
jdk.VirtualThreadPinned {
startTime = 19:38:45.982 (2026-11-18)
duration = 125 ms
blockingOperation = "LockSupport.park"
pinnedReason = "VM call to Solution$ExchangeRates.<clinit> on stack"
carrierThread = "ForkJoinPool-1-worker-7" (javaThreadId = 41)
eventThread = "" (javaThreadId = 1042, virtual)
stackTrace = [
...
The pinnedReason and blockingOperation fields, added in Java 24, say why the thread couldn't unmount and what it was blocked in. On Java 21–23 the event has only the duration and stack trace. For a graphical view, open the file in JDK Mission Control, which has pages for threads, locks and event browsing.
Streaming events in-process
Since Java 14, jdk.jfr.consumer.RecordingStream lets an application subscribe to its own JFR events while it runs. This is useful for alerts ("log a warning when anything pins for more than 50 ms"), for exporting metrics, and for tests that check a code path doesn't pin. The program below enables all four virtual-thread events, runs 1,000 ordinary waiting tasks and one task that initializes a class with a slow static block, and reports what JFR saw:
import java.time.Duration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordedFrame;
import jdk.jfr.consumer.RecordingStream;
public class Solution {
static void pause(long ms) {
try { Thread.sleep(ms); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
}
/** Loads "rates" in its static initializer, with a slow call: this pins whoever initializes it. */
static class ExchangeRates {
static final double EUR_PER_USD;
static { pause(120); EUR_PER_USD = 0.92; }
}
static final AtomicInteger started = new AtomicInteger(), ended = new AtomicInteger();
static void onPinned(RecordedEvent e) {
String where = e.getStackTrace().getFrames().stream()
.map(RecordedFrame::getMethod)
.filter(m -> m.getType().getName().startsWith("Solution"))
.map(m -> m.getType().getName() + "." + m.getName())
.limit(2)
.collect(java.util.stream.Collectors.joining(" <- "));
long ms = Math.round(e.getDuration().toMillis() / 10.0) * 10;
System.out.println("PINNED for about " + ms + " ms");
System.out.println(" blocking operation: " + e.getString("blockingOperation"));
System.out.println(" reason: " + e.getString("pinnedReason"));
System.out.println(" in our code at: " + where);
}
public static void main(String[] args) throws Exception {
try (RecordingStream jfr = new RecordingStream()) {
jfr.enable("jdk.VirtualThreadStart"); // off by default: one per thread
jfr.enable("jdk.VirtualThreadEnd");
jfr.enable("jdk.VirtualThreadPinned").withThreshold(Duration.ofMillis(20)).withStackTrace();
jfr.enable("jdk.VirtualThreadSubmitFailed");
jfr.onEvent("jdk.VirtualThreadStart", e -> started.incrementAndGet());
jfr.onEvent("jdk.VirtualThreadEnd", e -> ended.incrementAndGet());
jfr.onEvent("jdk.VirtualThreadPinned", Solution::onPinned);
jfr.onEvent("jdk.VirtualThreadSubmitFailed", e -> System.out.println("SUBMIT FAILED: " + e));
jfr.startAsync();
Thread.sleep(500); // let the recording start
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 1_000; i++) executor.submit(() -> pause(30)); // ordinary waiting
executor.submit(() -> ExchangeRates.EUR_PER_USD); // one pinning event
}
Thread.sleep(1500); // let JFR flush the events
System.out.println("virtual threads started: " + started.get() + ", ended: " + ended.get());
}
}
}
Output on Java 25:
PINNED for about 120 ms
blocking operation: LockSupport.park
reason: VM call to Solution$ExchangeRates.<clinit> on stack
in our code at: Solution.pause <- Solution$ExchangeRates.<clinit>
virtual threads started: 1001, ended: 1001
A thousand virtual threads slept without a single pinning event, because Thread.sleep unmounts. The one pinning event points exactly at the static initializer, and the reason names it. JFR delivers events in batches about once a second, which is why the program waits before printing the counts. A real alerting hook simply leaves the stream running.
What to look for
- Pinning events in hot paths. A few events at startup, from class initialization, are normal. Hundreds per minute from the same request path aren't. Group by stack trace (
jfr view pinned-threadsdoes that) and fix the top entries first, usually by upgrading a library or moving a slow native call to a platform pool (article 14). - Any
VirtualThreadSubmitFailedevent. It means the scheduler couldn't accept a virtual thread, typically because of memory exhaustion. Treat it as an incident. - Thread counts and lifetimes, from the lifecycle events during a test run. They show whether virtual threads are really short-lived per task, or whether something keeps thousands alive.
- The usual metrics: CPU use, GC pauses and heap. Virtual threads move stacks to the heap, so a migration can change GC behavior. Track latency percentiles and throughput before and after.
What's current
- Java 24 added
pinnedReason,blockingOperationandcarrierThreadtojdk.VirtualThreadPinned, so each event says whether a monitor, a native frame or class initialization was the cause. jfr view(since Java 21) has predefined views, includingpinned-threads. Runjfr viewwithout arguments to list them.-Djdk.tracePinnedThreads, the older way of printing pinned stacks to the console, was removed in Java 24. JFR replaces it.- JDK Mission Control is released separately from the JDK and reads recordings from any recent JDK.
Common questions
Is it safe to keep JFR on in production?
Yes. The default settings are designed to cost about 1% of performance or less, which is why many teams run a continuous recording and dump it when something goes wrong. Enabling VirtualThreadStart/End in a high-throughput service is the exception: keep that for short runs.
Why didn't my pinning show up?
The event is recorded only when a pinned virtual thread blocks for longer than the threshold (20 ms by default). Short pinned sections, or pinned code that never blocks, don't produce events. Lower the threshold, for example jdk.VirtualThreadPinned#threshold=5ms, to see shorter ones.
Can JFR show CPU-bound virtual threads hogging carriers? Not with the virtual-thread events, since nothing is pinned or blocked. Use JFR's execution samples (method profiling) and a thread dump (article 17) to see which virtual threads are running.
Do I need JDK Mission Control?
No. jfr view, jfr print and jfr summary are enough for most investigations, and jfr print --json produces output for scripts.
Summary
- JFR records
jdk.VirtualThreadPinned(by default, over 20 ms) andjdk.VirtualThreadSubmitFailed. Lifecycle events exist but are off by default. - Record with
-XX:StartFlightRecordingorjcmd <pid> JFR.start, and add settings inline or withjfr configure. - Read recordings with
jfr view pinned-threads,jfr summaryandjfr print, or JDK Mission Control. - Since Java 24, pinned events include the reason, the blocking operation and the carrier.
RecordingStreamdelivers events in-process, for alerts, metrics and tests.
Practice questions
A team enables jdk.VirtualThreadStart and jdk.VirtualThreadEnd permanently on a service that handles 20,000 requests per second, one virtual thread each. What's the problem?
Answer
It records 40,000 lifecycle events per second, more than everything else JFR normally records, which increases overhead and fills the recording buffers and files quickly. Keep the default settings in production, and enable lifecycle events only for short diagnostic runs.
A recording from a Java 21 service shows no jdk.VirtualThreadPinned events, but throughput drops whenever a nightly job runs a long computation on virtual threads. Why doesn't JFR show pinning, and what would you look at instead?
Answer
CPU-bound virtual threads aren't pinned. They simply never block, so they keep their carriers and no pinning event is recorded. Look at execution samples (which methods use the CPU) and thread dumps, then move the computation to a pool sized to the cores.
Which command would you run to see, for a running JVM with PID 4242, which methods pinned virtual threads in the last two minutes?
Answer
Start a recording with jcmd 4242 JFR.start name=vt duration=2m filename=vt.jfr, wait for it to finish, then run jfr view pinned-threads vt.jfr. (If a continuous recording is already running, jcmd 4242 JFR.dump writes its current contents to a file instead.)
Previous: ThreadLocal With Java Virtual Threads: Memory Costs, Inheritance and Alternatives
Next: Java Virtual Thread Dumps With jcmd: JSON Format, Thread Containers and HotSpotDiagnosticMXBean

More in Modern Java Concurrency
Quiz: Java Concurrency Changes From Java 21 to Java 28
Sixteen questions on what changed release by release: virtual threads final in 21, synchronized without pinning in 24, scoped values final in 25, and the long road of structured concurrency from subclasses to open() and Joiner, the Java 26 and 27 refinements, and final in 28.
Quiz: Java Concurrency's Delicate Details
Twenty edge cases of modern Java concurrency that surprise experienced developers: virtual thread priorities and names, semaphores without owners, null scoped values, cancelling a CompletableFuture, pool sizing with unbounded queues, and StructuredTaskScope's strict rules.
Quiz: Java Concurrency Interview Questions (Virtual Threads, Structured Concurrency, Scoped Values)
Twenty questions of the kind interviewers ask about modern Java concurrency: platform vs virtual threads, pinning, pools and limits, CompletableFuture, structured concurrency, scoped values vs ThreadLocal, reactive programming, and production diagnostics.
Quiz: Modern Java Concurrency Final Exam (All 7 Parts)
The final exam for the modern Java concurrency course: thirty questions across all seven parts, from platform threads, pools and CompletableFuture through virtual threads, the scheduler, structured concurrency, scoped values, reactive streams and frameworks.
Discussion
Sign in to ask a question or share what you learned.