用Java获取内存统计信息:运行时与MemoryMXBean [英] Getting Memory Statistics in Java: Runtime vs. MemoryMXBean
问题描述
我正在创建一个计划执行程序来读取JVM的内存使用情况.我遇到了两种在运行的JVM中获取内存统计信息的方法-Runtime& MemoryMXBean,其方法之间具有以下对应关系:
I am creating a scheduled executor to read the memory usage of the JVM. I have come across two ways to get memory statistics in a running JVM - Runtime & MemoryMXBean, with the following correspondence between their methods:
memoryMxBean.getHeapMemoryUsage().getUsed() <=> runtime.totalMemory() - runtime.freeMemory()
memoryMxBean.getHeapMemoryUsage().getCommitted() <=> runtime.totalMemory()
memoryMxBean.getHeapMemoryUsage().getMax() <=> runtime.maxMemory()
除了MemoryMXBean提供的其他非堆内存使用信息之外,是否有任何原因使我比运行时更喜欢它,反之亦然?
With the exception of the additional non-heap memory usage information provided by MemoryMXBean, are there any reasons why I should prefer it over Runtime, or vice-versa?
推荐答案
没有. JMX bean可以从外部访问,用于管理工具,例如 hyperic(甚至nagios)-无论如何它将委托给Runtime.
There are none. JMX bean can be accessed externally and is meant for management tools like hyperic ( or even nagios ) - It would delegate to Runtime anyway.
这篇关于用Java获取内存统计信息:运行时与MemoryMXBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!