當前位置: 首頁>>代碼示例>>Java>>正文


Java ManagementFactory.getMemoryPoolMXBeans方法代碼示例

本文整理匯總了Java中java.lang.management.ManagementFactory.getMemoryPoolMXBeans方法的典型用法代碼示例。如果您正苦於以下問題:Java ManagementFactory.getMemoryPoolMXBeans方法的具體用法?Java ManagementFactory.getMemoryPoolMXBeans怎麽用?Java ManagementFactory.getMemoryPoolMXBeans使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getMemoryPoolMXBeans方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import java.lang.management.ManagementFactory; //導入方法依賴的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);
        }
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:GarbageCollectionCheck.java

示例2: getAllMemoryPoolNames

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
/**
 * Returns the names of all available memory pools as a single string.
 */
private static String getAllMemoryPoolNames() {
  StringBuilder builder = new StringBuilder("[");

  for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getMemoryPoolMXBeans()) {
    builder.append("(Name=").append(memoryPoolBean.getName()).append(";Type=")
        .append(memoryPoolBean.getType()).append(";UsageThresholdSupported=")
        .append(memoryPoolBean.isUsageThresholdSupported()).append("), ");
  }

  if (builder.length() > 1) {
    builder.setLength(builder.length() - 2);
  }
  builder.append("]");

  return builder.toString();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:20,代碼來源:HeapMemoryMonitor.java

示例3: main

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    boolean verified = false;
    for (MemoryPoolMXBean i : pools) {
        if ((i.getUsage().getMax() >= TWO_G)
                && i.isUsageThresholdSupported()) {
            i.setUsageThreshold(TWO_G);
            if(i.getUsageThreshold() != TWO_G)
                throw new RuntimeException("Usage threshold for"
                        + " pool '" + i.getName() + "' is " + i.getUsageThreshold()
                        + " and not equal to 2GB");
            verified = true;
        }
    }
    System.out.println("Ability to use big heap thresholds has "
            + (verified ? "" : "NOT ") + "been verified");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:LargeHeapThresholdTest.java

示例4: setMemThreshold

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private void setMemThreshold()
{
	m_bMaxPermanentHeap_MoSet = false;

	List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
	for (MemoryPoolMXBean p: pools)
	{
		if(p.getType().compareTo(MemoryType.HEAP) == 0)
		{
			String cs = p.getName();
			if(cs.equalsIgnoreCase("Tenured gen"))
			{
				long l = 1024L * 1024L * (long)m_nMaxPermanentHeap_Mo;
				p.setUsageThreshold(l);
				m_tenuredPool = p;
			}				
		}
	}
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:20,代碼來源:ThreadStatementGC.java

示例5: getUsage

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
/**
 * Get MemoryUsage from MemoryPoolMXBean which name matches passed string.
 *
 * @param name
 * @return MemoryUsage
 */
private static MemoryUsage getUsage(String name){
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (pool.getName().matches(name)) {
            return pool.getUsage();
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:HeapRegionUsageTool.java

示例6: reportMemoryPool

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private void reportMemoryPool() {
    for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        log.info("Memory Pool {} - type=\"{}\" memory-manager=\"{}\"", pool.getName(), pool.getType(), Joiner.on(',').join(pool.getMemoryManagerNames()));
        log.info("Memory Pool {} - Usage            {}", pool.getName(), pool.getUsage());
        log.info("Memory Pool {} - Collection Usage {}", pool.getName(), pool.getCollectionUsage());
        log.info("Memory Pool {} - Peak Usage       {}", pool.getName(), pool.getPeakUsage());
        log.info("Memory Pool {} - Type             {}", pool.getName(), pool.getPeakUsage());
    }
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:10,代碼來源:MemoryReporterService.java

示例7: main

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
public static void main(String[] args) {

        List<MemoryPoolMXBean> pmbList = ManagementFactory.getMemoryPoolMXBeans();

        for (MemoryPoolMXBean mpmb : pmbList) {
            System.out.println(mpmb.getName());
        }
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:9,代碼來源:doTestJVMMBean.java

示例8: JvmGcMetrics

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
public JvmGcMetrics(Iterable<Tag> tags) {
    for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
        if (isYoungGenPool(mbean.getName()))
            youngGenPoolName = mbean.getName();
        if (isOldGenPool(mbean.getName()))
            oldGenPoolName = mbean.getName();
    }
    this.tags = tags;
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:10,代碼來源:JvmGcMetrics.java

示例9: checkGcInfo

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private static void checkGcInfo(String name, GcInfo info) throws Exception {
    System.out.println("GC statistic for : " + name);
    System.out.print("GC #" + info.getId());
    System.out.print(" start:" + info.getStartTime());
    System.out.print(" end:" + info.getEndTime());
    System.out.println(" (" + info.getDuration() + "ms)");
    Map usage = info.getMemoryUsageBeforeGc();

    List pnames = new ArrayList();
    for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        String poolname = (String) entry.getKey();
        pnames.add(poolname);
        MemoryUsage busage = (MemoryUsage) entry.getValue();
        MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
        if (ausage == null) {
            throw new RuntimeException("After Gc Memory does not exist" +
                " for " + poolname);
        }
        System.out.println("Usage for pool " + poolname);
        System.out.println("   Before GC: " + busage);
        System.out.println("   After GC: " + ausage);
    }

    // check if memory usage for all memory pools are returned
    List pools = ManagementFactory.getMemoryPoolMXBeans();
    for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
        MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
        if (!pnames.contains(p.getName())) {
            throw new RuntimeException("GcInfo does not contain " +
                "memory usage for pool " + p.getName());
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:LastGCInfo.java

示例10: findPool

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private static MemoryPoolMXBean findPool(String poolName) {
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (pool.getName().contains(poolName)) {
            return pool;
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:Pools.java

示例11: getAllPoolNames

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
synchronized String[] getAllPoolNames() {
    if (poolNames == null) {
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
        poolNames = new String[pools.size()];
        int i = 0;
        for (MemoryPoolMXBean m : pools) {
            poolNames[i++] = m.getName();
        }
    }
    return poolNames;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:GarbageCollectorImpl.java

示例12: printUsage

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
/**
 * Выводит в stdout информацию о текущем состоянии различных разделов памяти.
 */
public static void printUsage(boolean heapOnly) {
    for(MemoryPoolMXBean mBean: ManagementFactory.getMemoryPoolMXBeans()) {
        if (!heapOnly || mBean.getType() == MemoryType.HEAP) {
            printMemUsage(mBean.getName(), mBean.getUsage());
        }
    }
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:11,代碼來源:MemoryUtil.java

示例13: DumpMemories

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
DumpMemories()
{
	List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
	for (MemoryPoolMXBean p: pools)
	{
		System.out.println("Memory type="+p.getType()+" Memory usage="+p.getUsage());
	}
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:9,代碼來源:DumpMemories.java

示例14: getMemoryPool

import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private static MemoryPoolMXBean getMemoryPool(String name) {
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean pool : pools) {
        if (pool.getName().equals(name)) {
            return pool;
        }
    }

    throw new RuntimeException("Expected to find a memory pool with name " + name);
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:11,代碼來源:TestMetaspaceMemoryPool.java

示例15: jvmStats

import java.lang.management.ManagementFactory; //導入方法依賴的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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:60,代碼來源:JvmStats.java


注:本文中的java.lang.management.ManagementFactory.getMemoryPoolMXBeans方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。