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

The following are Jave code examples for showing how to use resetPeakUsage() 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: 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 2
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 ;
}