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