Java25 jcmd Thread.vthread 相关命令源码解析

Java jcmd juc About 1,302 words

Attach Listener

Attach Listener通过监听jcmd的命令,执行相关逻辑。

at java.util.concurrent.ForkJoinPool.<clinit>(ForkJoinPool.java:200)
at java.lang.VirtualThread.createDefaultScheduler(VirtualThread.java:1444)
at java.lang.VirtualThread.<clinit>(VirtualThread.java:66)
at java.lang.System$1.virtualThreadDefaultScheduler(System.java:2308)
at jdk.internal.vm.JcmdVThreadCommands.printScheduler(JcmdVThreadCommands.java:50)

JcmdVThreadCommands

真实调用的是JcmdVThreadCommandsprintScheduler方法。

JLA.virtualThreadDefaultScheduler()native方法,JVM会返回当前的调度器。

默认调度器是VirtualThread类中的DEFAULT_SCHEDULERForkJoinPool对象)

package jdk.internal.vm;

/**
 * The implementation for the jcmd Thread.vthread_* diagnostic commands. These methods are
 * called from the "Attach Listener" thread.
 */
public class JcmdVThreadCommands {
    private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();

    private JcmdVThreadCommands() { }

    /**
     * Invoked by the VM to print the virtual scheduler to a byte[].
     */
    private static byte[] printScheduler() {
        StringBuilder sb = new StringBuilder();

        // virtual thread scheduler
        sb.append(JLA.virtualThreadDefaultScheduler())
          .append(System.lineSeparator());

        return sb.toString().getBytes(StandardCharsets.UTF_8);
    }
    
}
Views: 11 · Posted: 2025-12-30

———         Thanks for Reading         ———

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Prev Post
Today In History
Browsing Refresh