当前位置: 首页>>代码示例>>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;未经允许,请勿转载。