Example usage for java.lang.management MemoryPoolMXBean getUsage

List of usage examples for java.lang.management MemoryPoolMXBean getUsage

Introduction

In this page you can find the example usage for java.lang.management MemoryPoolMXBean getUsage.

Prototype

public MemoryUsage getUsage();

Source Link

Document

Returns an estimate of the memory usage of this memory pool.

Usage

From source file:org.mifos.framework.ApplicationInitializer.java

private void printMemoryPool() {
    logger.info("Memory MXBean");
    logger.info("Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
    logger.info("Non-Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage());

    logger.info("-----Memory Pool MXBeans------");

    Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator();

    while (iter.hasNext()) {
        MemoryPoolMXBean item = iter.next();

        logger.info("Name: " + item.getName());
        logger.info("Type: " + item.getType());
        logger.info("Usage: " + item.getUsage());
        logger.info("Peak Usage: " + item.getPeakUsage());
        logger.info("Collection Usage: " + item.getCollectionUsage());
        logger.info("+++++++++++++++++++");
    }//w  w w  .  j a va2  s.co  m
}

From source file:org.rhq.enterprise.agent.promptcmd.GCPromptCommand.java

private void printCurrentMemoryUsage(PrintWriter out) {
    final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
    printGlobalMemoryUsage(out, memoryMxBean);

    List<MemoryPoolMXBean> poolMxBeans = ManagementFactory.getMemoryPoolMXBeans();
    if (poolMxBeans != null) {
        for (MemoryPoolMXBean bean : poolMxBeans) {
            if (bean.isValid()) {
                String name = bean.getName();
                MemoryType type = bean.getType();
                MemoryUsage usage = bean.getUsage();
                printMemoryUsage(out, name, type, usage);
            }/*  w w w.  j a va2s . c o  m*/
        }
    }

    return;
}

From source file:org.toobsframework.management.MemoryMonitor.java

public static void setUsageThreshold(MemoryPoolMXBean memPool, double percentage) {
    MemoryUsage memUsage = memPool.getUsage();
    long max = memUsage.getMax();
    memPool.setUsageThreshold((long) (max * percentage));
}