1919import java .lang .management .ManagementFactory ;
2020import java .lang .management .MemoryMXBean ;
2121import java .lang .management .MemoryUsage ;
22+ import java .lang .management .PlatformManagedObject ;
2223
2324/**
2425 * Information about the process of the application.
2526 *
2627 * @author Jonatan Ivanov
28+ * @author Andrey Litvitski
2729 * @since 3.3.0
2830 */
2931public class ProcessInfo {
@@ -72,6 +74,31 @@ public MemoryInfo getMemory() {
7274 return new MemoryInfo ();
7375 }
7476
77+ /**
78+ * Virtual threads information for the process. These values provide details about the
79+ * current state of virtual threads, including the number of mounted threads, queued
80+ * threads, the parallelism level, and the thread pool size.
81+ * @return an instance of {@link VirtualThreadsInfo} containing information about
82+ * virtual threads, or {@code null} if the VirtualThreadSchedulerMXBean is not
83+ * available.
84+ * @since 3.5.0
85+ */
86+ @ SuppressWarnings ("unchecked" )
87+ public VirtualThreadsInfo getVirtualThreads () {
88+ try {
89+ Class <PlatformManagedObject > mxBeanClass = (Class <PlatformManagedObject >) Class
90+ .forName ("jdk.management.VirtualThreadSchedulerMXBean" );
91+ Object bean = ManagementFactory .getPlatformMXBean (mxBeanClass );
92+ return new VirtualThreadsInfo ((Integer ) mxBeanClass .getMethod ("getMountedVirtualThreadCount" ).invoke (bean ),
93+ (Long ) mxBeanClass .getMethod ("getQueuedVirtualThreadCount" ).invoke (bean ),
94+ (Integer ) mxBeanClass .getMethod ("getParallelism" ).invoke (bean ),
95+ (Integer ) mxBeanClass .getMethod ("getPoolSize" ).invoke (bean ));
96+ }
97+ catch (ReflectiveOperationException ex ) {
98+ return null ;
99+ }
100+ }
101+
75102 public long getPid () {
76103 return this .pid ;
77104 }
@@ -84,6 +111,46 @@ public String getOwner() {
84111 return this .owner ;
85112 }
86113
114+ /**
115+ * Virtual threads information.
116+ *
117+ * @since 3.5.0
118+ */
119+ public static class VirtualThreadsInfo {
120+
121+ private final int mounted ;
122+
123+ private final long queued ;
124+
125+ private final int parallelism ;
126+
127+ private final int poolSize ;
128+
129+ public VirtualThreadsInfo (int mounted , long queued , int parallelism , int poolSize ) {
130+ this .mounted = mounted ;
131+ this .queued = queued ;
132+ this .parallelism = parallelism ;
133+ this .poolSize = poolSize ;
134+ }
135+
136+ public long getMounted () {
137+ return this .mounted ;
138+ }
139+
140+ public long getQueued () {
141+ return this .queued ;
142+ }
143+
144+ public int getParallelism () {
145+ return this .parallelism ;
146+ }
147+
148+ public int getPoolSize () {
149+ return this .poolSize ;
150+ }
151+
152+ }
153+
87154 /**
88155 * Memory information.
89156 *
0 commit comments