Category Archives: tomcat src reading

tomcat src – org.apache.tomcat.util.Diagnostics.java

this java file is to print out diagnostics for tomcat and jvm system information

the mainly thing is to use java.lang.management.*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// init Bean class to dump system info
	private static final ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
	private static final CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean();
	private static final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	private static final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
	private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
 
	private static final PlatformLoggingMXBean loggingMXBean = ManagementFactory
			.getPlatformMXBean(PlatformLoggingMXBean.class);
	private static final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
	private static final List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory
			.getGarbageCollectorMXBeans();
	private static final List<MemoryManagerMXBean> memoryManagerMXBeans = ManagementFactory.getMemoryManagerMXBeans();
	private static final List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();

One of examples to print out vmName and vmVersion and so on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
StringBuilder sb = new StringBuilder();
 
		synchronized (timeformat) {
			sb.append(timeformat.format(new Date()));
		}
		sb.append(CRLF);
 
		sb.append(requestedSm.getString("diagnostics.vmInfoRuntime"));
		sb.append(":" + CRLF);
		sb.append(INDENT1 + "vmName: " + runtimeMXBean.getVmName() + CRLF);
		sb.append(INDENT1 + "vmVersion: " + runtimeMXBean.getVmVersion() + CRLF);
		sb.append(INDENT1 + "vmVendor: " + runtimeMXBean.getVmVendor() + CRLF);
		sb.append(INDENT1 + "specName: " + runtimeMXBean.getSpecName() + CRLF);
		sb.append(INDENT1 + "specVersion: " + runtimeMXBean.getSpecVersion() + CRLF);
		sb.append(INDENT1 + "specVendor: " + runtimeMXBean.getSpecVendor() + CRLF);
		sb.append(INDENT1 + "managementSpecVersion: " + runtimeMXBean.getManagementSpecVersion() + CRLF);
		sb.append(INDENT1 + "name: " + runtimeMXBean.getName() + CRLF);
		sb.append(INDENT1 + "startTime: " + runtimeMXBean.getStartTime() + CRLF);
		sb.append(INDENT1 + "uptime: " + runtimeMXBean.getUptime() + CRLF);
		sb.append(INDENT1 + "isBootClassPathSupported: " + runtimeMXBean.isBootClassPathSupported() + CRLF);
		sb.append(CRLF);