Example usage for java.lang.management MemoryPoolMXBean getCollectionUsage

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

Introduction

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

Prototype

public MemoryUsage getCollectionUsage();

Source Link

Document

Returns the memory usage after the Java virtual machine most recently expended effort in recycling unused objects in this memory pool.

Usage

From source file:io.ecarf.core.utils.Utils.java

/**
 * Log memory usage//from  w ww.  java  2 s . c  o  m
 * @return
 */
public static long getMemoryUsage() {
    List<MemoryPoolMXBean> memoryPools = new ArrayList<MemoryPoolMXBean>(
            ManagementFactory.getMemoryPoolMXBeans());
    long usedHeapMemoryAfterLastGC = 0;
    for (MemoryPoolMXBean memoryPool : memoryPools) {
        if (memoryPool.getType().equals(MemoryType.HEAP)) {
            MemoryUsage poolCollectionMemoryUsage = memoryPool.getCollectionUsage();
            usedHeapMemoryAfterLastGC += poolCollectionMemoryUsage.getUsed();
        }
    }
    return usedHeapMemoryAfterLastGC;
}

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("+++++++++++++++++++");
    }//from  w w w.  j  av  a  2  s .c o  m
}