-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListJVMBeans.java
More file actions
29 lines (27 loc) · 1.2 KB
/
ListJVMBeans.java
File metadata and controls
29 lines (27 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import javax.management.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
public class ListJVMBeans {
public static void main(String[] args) throws IOException {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("jvm-mbeans"));
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
Set names = mBeanServer.queryNames(null, null);
for (Object mbeanName : names) {
ObjectName objectName = (ObjectName) mbeanName;
writer.write("MBean: " + objectName + "\n");
MBeanAttributeInfo[] attributes = mBeanServer.getMBeanInfo(objectName).getAttributes();
String list = Arrays.asList(attributes).stream().map(info -> info.getName()).collect(Collectors.joining(","));
writer.write("Attributes: " + list + "\n\n");
}
writer.close();
} catch (InstanceNotFoundException | IntrospectionException | ReflectionException e) {
e.printStackTrace();
}
}
}