本文整理匯總了Java中java.lang.management.MemoryPoolMXBean.getPeakUsage方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryPoolMXBean.getPeakUsage方法的具體用法?Java MemoryPoolMXBean.getPeakUsage怎麽用?Java MemoryPoolMXBean.getPeakUsage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.MemoryPoolMXBean
的用法示例。
在下文中一共展示了MemoryPoolMXBean.getPeakUsage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: poolSummaries
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
/**
* Returns a summary information about the memory pools.
*/
public static String poolSummaries() {
// Why ? list-archive?4273859
// How ? http://stackoverflow.com/questions/697336/how-do-i-programmatically-find-out-my-permgen-space-usage
// http://stackoverflow.com/questions/8356416/xxmaxpermsize-with-or-without-xxpermsize
StringBuilder sb = new StringBuilder();
Iterator<MemoryPoolMXBean> iter =
ManagementFactory.getMemoryPoolMXBeans().iterator();
while (iter.hasNext()) {
MemoryPoolMXBean item = iter.next();
String name = item.getName();
MemoryType type = item.getType();
MemoryUsage usage = item.getUsage();
MemoryUsage peak = item.getPeakUsage();
MemoryUsage collections = item.getCollectionUsage();
sb.append(String.format("Memory pool name: " + name
+ ", type: " + type
+ ", usage: " + usage
+ ", peak: " + peak
+ ", collections: " + collections
+ "\n"));
}
return sb.toString();
}
示例2: jvmStats
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static JvmStats jvmStats() {
MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
memUsage = memoryMXBean.getNonHeapMemoryUsage();
long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
List<MemoryPool> pools = new ArrayList<>();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
try {
MemoryUsage usage = memoryPoolMXBean.getUsage();
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
continue;
}
pools.add(new MemoryPool(name,
usage.getUsed() < 0 ? 0 : usage.getUsed(),
usage.getMax() < 0 ? 0 : usage.getMax(),
peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
));
} catch (Exception ex) {
/* ignore some JVMs might barf here with:
* java.lang.InternalError: Memory Pool not found
* we just omit the pool in that case!*/
}
}
Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());
List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
for (int i = 0; i < collectors.length; i++) {
GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()),
gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
}
GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
List<BufferPool> bufferPoolsList = Collections.emptyList();
try {
List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
bufferPoolsList = new ArrayList<>(bufferPools.size());
for (BufferPoolMXBean bufferPool : bufferPools) {
bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(),
bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
}
} catch (Exception e) {
// buffer pools are not available
}
Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(),
classLoadingMXBean.getUnloadedClassCount());
return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads,
garbageCollectors, bufferPoolsList, classes);
}