本文整理匯總了Java中java.lang.management.MemoryPoolMXBean.getCollectionUsage方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryPoolMXBean.getCollectionUsage方法的具體用法?Java MemoryPoolMXBean.getCollectionUsage怎麽用?Java MemoryPoolMXBean.getCollectionUsage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.MemoryPoolMXBean
的用法示例。
在下文中一共展示了MemoryPoolMXBean.getCollectionUsage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
@Override
public void run() {
List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
@Override
public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
return mbean.getName().equals(garbageCollector);
}
});
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
String pool = memoryPoolMXBean.getName();
if (memoryPools.contains(pool)) {
GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
events.get(pool).slideAndInsert(event);
}
}
}
示例2: 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();
}