Example usage for java.lang.management MemoryPoolMXBean isUsageThresholdSupported

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

Introduction

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

Prototype

public boolean isUsageThresholdSupported();

Source Link

Document

Tests if this memory pool supports usage threshold.

Usage

From source file:org.apache.pig.impl.util.SpillableMemoryManager.java

private SpillableMemoryManager() {
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
    List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
    long totalSize = 0;
    for (MemoryPoolMXBean pool : mpbeans) {
        log.debug("Found heap (" + pool.getName() + ") of type " + pool.getType());
        if (pool.getType() == MemoryType.HEAP) {
            long size = pool.getUsage().getMax();
            totalSize += size;/*from www.  jav a2  s . c  om*/
            // CMS Old Gen or "tenured" is the only heap that supports
            // setting usage threshold.
            if (pool.isUsageThresholdSupported()) {
                tenuredHeap = pool;
            }
        }
    }
    extraGCSpillSizeThreshold = (long) (totalSize * extraGCThresholdFraction);
    if (tenuredHeap == null) {
        throw new RuntimeException("Couldn't find heap");
    }

    configureMemoryThresholds(MEMORY_THRESHOLD_FRACTION_DEFAULT, COLLECTION_THRESHOLD_FRACTION_DEFAULT,
            UNUSED_MEMORY_THRESHOLD_DEFAULT);

}

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

private void init() {
    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    ((NotificationBroadcaster) mem).addNotificationListener(listener, null, null);

    for (MemoryPoolMXBean memPool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (memPool.isUsageThresholdSupported()) {
            memPools.put(memPool.getName(), memPool);
            log.info("Putting Pool " + memPool.getName());
            setUsageThreshold(memPool, 0.7);
        }//from w  w  w  .j av a 2  s  . c  o m
    }
}