APIdia Launch Partner
Top Description Methods
jdk.management

public Interface VirtualThreadSchedulerMXBean

extends PlatformManagedObject
Known Direct Implementers
com.sun.management.internal.VirtualThreadSchedulerImpls.BaseVirtualThreadSchedulerImpl
Imports
java.lang.management.ManagementFactory, .PlatformManagedObject, java.util.concurrent.ForkJoinPool, javax.management.MBeanServer, .ObjectName

Management interface for the JDK's virtual thread scheduler.

VirtualThreadSchedulerMXBean supports monitoring of the virtual thread scheduler's target parallelism, the platform threads used by the scheduler, and the number of virtual threads queued to the scheduler. It also supports dynamically changing the scheduler's target parallelism.

The management interface is registered with the platform MBeanServer. The ObjectName that uniquely identifies the management interface within the MBeanServer is: "jdk.management:type=VirtualThreadScheduler".

Direct access to the MXBean interface can be obtained with ManagementFactory#getPlatformMXBean(Class).

Since
24

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

an estimate of the number of virtual threads that are currently mounted by the scheduler; -1 if not known
getMountedVirtualThreadCount
()

Returns an estimate of the number of virtual threads that are currently mounted by the scheduler; -1 if not known.

public int

Returns:

the scheduler's target parallelism
getParallelism
()

Returns the scheduler's target parallelism.

public int

Returns:

the current number of platform threads that the scheduler has started but have not terminated; -1 if not known
getPoolSize
()

Returns the current number of platform threads that the scheduler has started but have not terminated; -1 if not known.

public long

Returns:

an estimate of the number of virtual threads that are queued to the scheduler to start or continue execution; -1 if not known
getQueuedVirtualThreadCount
()

Returns an estimate of the number of virtual threads that are queued to the scheduler to start or continue execution; -1 if not known.

public void
setParallelism(int
the target parallelism level
size
)

Sets the scheduler's target parallelism.

Inherited from java.lang.management.PlatformManagedObject:
getObjectName

Method Detail

getMountedVirtualThreadCountback to summary
public int getMountedVirtualThreadCount()

Returns an estimate of the number of virtual threads that are currently mounted by the scheduler; -1 if not known.

The number of mounted virtual threads is equal to the number of platform threads carrying virtual threads.

Implementation Note

This method may overestimate the number of virtual threads that are mounted.

Returns:int

an estimate of the number of virtual threads that are currently mounted by the scheduler; -1 if not known

getParallelismback to summary
public int getParallelism()

Returns the scheduler's target parallelism.

Returns:int

the scheduler's target parallelism

See Also
ForkJoinPool#getParallelism()
getPoolSizeback to summary
public int getPoolSize()

Returns the current number of platform threads that the scheduler has started but have not terminated; -1 if not known.

The count includes the platform threads that are currently carrying virtual threads and the platform threads that are not currently carrying virtual threads. The thread count may be greater than the scheduler's target parallelism.

Implementation Note

The JDK's virtual thread scheduler is a ForkJoinPool. The pool size is the number of worker threads.

Returns:int

the current number of platform threads that the scheduler has started but have not terminated; -1 if not known

getQueuedVirtualThreadCountback to summary
public long getQueuedVirtualThreadCount()

Returns an estimate of the number of virtual threads that are queued to the scheduler to start or continue execution; -1 if not known.

Implementation Note

This method may overestimate the number of virtual threads that are queued to execute.

Returns:long

an estimate of the number of virtual threads that are queued to the scheduler to start or continue execution; -1 if not known

setParallelismback to summary
public void setParallelism(int size)

Sets the scheduler's target parallelism.

Increasing the target parallelism allows the scheduler to use more platform threads to carry virtual threads if required. Decreasing the target parallelism reduces the number of threads that the scheduler may use to carry virtual threads.

API Note

If virtual threads are mounting and unmounting frequently then downward adjustment of the target parallelism will likely come into effect quickly.

Implementation Note

The JDK's virtual thread scheduler is a ForkJoinPool. Target parallelism defaults to the number of available processors. The minimum target parallelism is 1, the maximum target parallelism is 32767.

Parameters
size:int

the target parallelism level

Exceptions
IllegalArgumentException:
if size is less than the minimum, or greater than the maximum, supported by the scheduler
UnsupportedOperationException:
if changing the target parallelism is not supported by the scheduler
See Also
ForkJoinPool#setParallelism(int)