24
24
* Information about the process of the application.
25
25
*
26
26
* @author Jonatan Ivanov
27
+ * @author Andrey Litvitski
27
28
* @since 3.3.0
28
29
*/
29
30
public class ProcessInfo {
@@ -72,6 +73,29 @@ public MemoryInfo getMemory() {
72
73
return new MemoryInfo ();
73
74
}
74
75
76
+ /**
77
+ * Virtual threads information for the process. These values provide details about the
78
+ * current state of virtual threads, including the number of mounted threads, queued threads,
79
+ * the parallelism level, and the thread pool size.
80
+ * @return an instance of {@link VirtualThreadsInfo} containing information about virtual threads,
81
+ * or {@code null} if the VirtualThreadSchedulerMXBean is not available.
82
+ * @since 3.5.0
83
+ */
84
+ public VirtualThreadsInfo getVirtualThreads () {
85
+ try {
86
+ Class mxBeanClass = Class .forName ("jdk.management.VirtualThreadSchedulerMXBean" );
87
+ Object bean = ManagementFactory .getPlatformMXBean (mxBeanClass );
88
+ return new VirtualThreadsInfo (
89
+ (Integer ) mxBeanClass .getMethod ("getMountedVirtualThreadCount" ).invoke (bean ),
90
+ (Long ) mxBeanClass .getMethod ("getQueuedVirtualThreadCount" ).invoke (bean ),
91
+ (Integer ) mxBeanClass .getMethod ("getParallelism" ).invoke (bean ),
92
+ (Integer ) mxBeanClass .getMethod ("getPoolSize" ).invoke (bean )
93
+ );
94
+ } catch (ReflectiveOperationException e ) {
95
+ return null ;
96
+ }
97
+ }
98
+
75
99
public long getPid () {
76
100
return this .pid ;
77
101
}
@@ -84,6 +108,46 @@ public String getOwner() {
84
108
return this .owner ;
85
109
}
86
110
111
+ /**
112
+ * Virtual threads information.
113
+ *
114
+ * @since 3.5.0
115
+ */
116
+ public static class VirtualThreadsInfo {
117
+
118
+ private final int mounted ;
119
+
120
+ private final long queued ;
121
+
122
+ private final int parallelism ;
123
+
124
+ private final int poolSize ;
125
+
126
+ public VirtualThreadsInfo (int mounted , long queued , int parallelism , int poolSize ) {
127
+ this .mounted = mounted ;
128
+ this .queued = queued ;
129
+ this .parallelism = parallelism ;
130
+ this .poolSize = poolSize ;
131
+ }
132
+
133
+ public long getMounted () {
134
+ return this .mounted ;
135
+ }
136
+
137
+ public long getQueued () {
138
+ return this .queued ;
139
+ }
140
+
141
+ public int getParallelism () {
142
+ return this .parallelism ;
143
+ }
144
+
145
+ public int getPoolSize () {
146
+ return this .poolSize ;
147
+ }
148
+
149
+ }
150
+
87
151
/**
88
152
* Memory information.
89
153
*
0 commit comments