< prev index next > src/jdk.management/share/classes/com/sun/management/internal/VirtualThreadSchedulerImpls.java
Print this page
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.management.internal;
- import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;
import javax.management.ObjectName;
import jdk.management.VirtualThreadSchedulerMXBean;
- import jdk.internal.access.JavaLangAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.vm.ContinuationSupport;
import sun.management.Util;
/**
private static final class VirtualThreadSchedulerImpl extends BaseVirtualThreadSchedulerImpl {
/**
* Holder class for scheduler.
*/
private static class Scheduler {
- private static final Executor scheduler =
- SharedSecrets.getJavaLangAccess().virtualThreadDefaultScheduler();
- static Executor instance() {
- return scheduler;
+ private static final Thread.VirtualThreadScheduler SCHEDULER =
+ SharedSecrets.getJavaLangAccess().defaultVirtualThreadScheduler();
+ static Thread.VirtualThreadScheduler instance() {
+ return SCHEDULER;
}
}
@Override
public int getParallelism() {
if (Scheduler.instance() instanceof ForkJoinPool pool) {
return pool.getParallelism();
}
- throw new InternalError(); // should not get here
+ return -1; // unknown
}
@Override
public void setParallelism(int size) {
if (Scheduler.instance() instanceof ForkJoinPool pool) {
pool.setParallelism(size);
if (pool.getPoolSize() < size) {
// FJ worker thread creation is on-demand
Thread.startVirtualThread(() -> { });
}
-
return;
}
- throw new UnsupportedOperationException(); // should not get here
+ throw new UnsupportedOperationException();
}
@Override
public int getPoolSize() {
if (Scheduler.instance() instanceof ForkJoinPool pool) {
return pool.getPoolSize();
}
- return -1; // should not get here
+ return -1; // unknown
}
@Override
public int getMountedVirtualThreadCount() {
if (Scheduler.instance() instanceof ForkJoinPool pool) {
return pool.getActiveThreadCount();
}
- return -1; // should not get here
+ return -1; // unknown
}
@Override
public long getQueuedVirtualThreadCount() {
if (Scheduler.instance() instanceof ForkJoinPool pool) {
return pool.getQueuedTaskCount() + pool.getQueuedSubmissionCount();
}
- return -1L; // should not get here
+ return -1L; // unknown
}
}
/**
* Implementation of VirtualThreadSchedulerMXBean when virtual threads are backed
< prev index next >