Java Code Examples for java.lang.management.MemoryPoolMXBean.isUsageThresholdSupported()

The following are Jave code examples for showing how to use isUsageThresholdSupported() of the java.lang.management.MemoryPoolMXBean class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: LargeHeapThresholdTest.java   View Source Code Vote up 6 votes
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");
}
 
Example 2
Project: abhot   File: MemoryMonitor.java   View Source Code Vote up 5 votes
private static MemoryPoolMXBean findPool()
{
	MemoryPoolMXBean ret = null;
	for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
		if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
			ret = pool;
		}
	}
	// we do something when we reached 99.9% of memory usage
	// when we get to this point gc was unable to recover memory.
	ret.setCollectionUsageThreshold((long) Math.floor(ret.getUsage().getMax() * 0.999));

	return (ret);
}
 
Example 3
Project: jdk8u-jdk   File: MXBeanInteropTest1.java   View Source Code Vote up 4 votes
private final int doMemoryPoolMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- MemoryPoolMXBean") ;

    try {
        ObjectName filterName =
                new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE
                + ",*");
        Set<ObjectName> onSet = mbsc.queryNames(filterName, null);

        for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
            ObjectName memoryPoolName = iter.next() ;
            System.out.println("-------- " + memoryPoolName) ;
            MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryPoolName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            MemoryPoolMXBean memoryPool = null;

            memoryPool =
                    JMX.newMXBeanProxy(mbsc,
                    memoryPoolName,
                    MemoryPoolMXBean.class,
                    true) ;
            System.out.println("getCollectionUsage\t\t"
                    + memoryPool.getCollectionUsage());
            System.out.println("getMemoryManagerNames\t\t"
                    + Arrays.deepToString(memoryPool.getMemoryManagerNames()));
            System.out.println("getName\t\t"
                    + memoryPool.getName());
            System.out.println("getPeakUsage\t\t"
                    + memoryPool.getPeakUsage());
            System.out.println("getType\t\t"
                    + memoryPool.getType());
            System.out.println("getUsage\t\t"
                    + memoryPool.getUsage());
            System.out.println("isValid\t\t"
                    + memoryPool.isValid());
            boolean supported = memoryPool.isUsageThresholdSupported() ;
            System.out.println("isUsageThresholdSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getUsageThreshold\t\t"
                        + memoryPool.getUsageThreshold());
                System.out.println("isUsageThresholdExceeded\t\t"
                        + memoryPool.isUsageThresholdExceeded());
                System.out.println("getUsageThresholdCount\t\t"
                        + memoryPool.getUsageThresholdCount());
            }

            supported = memoryPool.isCollectionUsageThresholdSupported() ;
            System.out.println("isCollectionUsageThresholdSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getCollectionUsageThreshold\t\t"
                        + memoryPool.getCollectionUsageThreshold());
                System.out.println("getCollectionUsageThresholdCount\t\t"
                        + memoryPool.getCollectionUsageThresholdCount());
                System.out.println("isCollectionUsageThresholdExceeded\t\t"
                        + memoryPool.isCollectionUsageThresholdExceeded());
            }

            memoryPool.resetPeakUsage();
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 4
Project: openjdk-jdk10   File: MXBeanInteropTest1.java   View Source Code Vote up 4 votes
private final int doMemoryPoolMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- MemoryPoolMXBean") ;

    try {
        ObjectName filterName =
                new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE
                + ",*");
        Set<ObjectName> onSet = mbsc.queryNames(filterName, null);

        for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
            ObjectName memoryPoolName = iter.next() ;
            System.out.println("-------- " + memoryPoolName) ;
            MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryPoolName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            MemoryPoolMXBean memoryPool = null;

            memoryPool =
                    JMX.newMXBeanProxy(mbsc,
                    memoryPoolName,
                    MemoryPoolMXBean.class,
                    true) ;
            System.out.println("getCollectionUsage\t\t"
                    + memoryPool.getCollectionUsage());
            System.out.println("getMemoryManagerNames\t\t"
                    + Arrays.deepToString(memoryPool.getMemoryManagerNames()));
            System.out.println("getName\t\t"
                    + memoryPool.getName());
            System.out.println("getPeakUsage\t\t"
                    + memoryPool.getPeakUsage());
            System.out.println("getType\t\t"
                    + memoryPool.getType());
            System.out.println("getUsage\t\t"
                    + memoryPool.getUsage());
            System.out.println("isValid\t\t"
                    + memoryPool.isValid());
            boolean supported = memoryPool.isUsageThresholdSupported() ;
            System.out.println("isUsageThresholdSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getUsageThreshold\t\t"
                        + memoryPool.getUsageThreshold());
                System.out.println("isUsageThresholdExceeded\t\t"
                        + memoryPool.isUsageThresholdExceeded());
                System.out.println("getUsageThresholdCount\t\t"
                        + memoryPool.getUsageThresholdCount());
            }

            supported = memoryPool.isCollectionUsageThresholdSupported() ;
            System.out.println("isCollectionUsageThresholdSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getCollectionUsageThreshold\t\t"
                        + memoryPool.getCollectionUsageThreshold());
                System.out.println("getCollectionUsageThresholdCount\t\t"
                        + memoryPool.getCollectionUsageThresholdCount());
                System.out.println("isCollectionUsageThresholdExceeded\t\t"
                        + memoryPool.isCollectionUsageThresholdExceeded());
            }

            memoryPool.resetPeakUsage();
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}