package com.ankurm.vthreads; /** * Standalone (no Spring context) check that -Djdk.tracePinnedThreads=full is inert on this * JDK. Pre-JDK-24, this flag made the JVM print a stack trace to stdout every time a virtual * thread pinned its carrier. JEP 491 removed the property along with most of the pinning it * used to report on: "setting it on the command line will have no effect." Run via * scripts/check-trace-pinned-threads-removed.sh, which invokes this twice (with and without * the flag) and diffs the output. See docs/03-pinning-diagnosis.md. */ public class PinningTraceCheckMain { public static void main(String[] args) throws Exception { System.out.println("java.version=" + System.getProperty("java.version")); System.out.println("jdk.tracePinnedThreads=" + System.getProperty("jdk.tracePinnedThreads")); System.out.println("Running a virtual thread that holds a monitor across Thread.sleep(200)..."); Thread vt = Thread.ofVirtual().start(() -> { try { PinningDemoService.doWorkHoldingMonitor(200); } catch (InterruptedException e) { throw new RuntimeException(e); } }); vt.join(); System.out.println("Done. If jdk.tracePinnedThreads still worked on this JDK, a pinned-thread " + "stack trace would have printed above while the virtual thread was inside doWorkHoldingMonitor."); } }