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,31 @@ 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
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
+
75
102
public long getPid () {
76
103
return this .pid ;
77
104
}
@@ -84,6 +111,46 @@ public String getOwner() {
84
111
return this .owner ;
85
112
}
86
113
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
+
87
154
/**
88
155
* Memory information.
89
156
*
0 commit comments