Java Code Examples for java.lang.management.MemoryPoolMXBean#isCollectionUsageThresholdSupported()

The following examples show how to use java.lang.management.MemoryPoolMXBean#isCollectionUsageThresholdSupported() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeapMonitorThread.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void registerForNotifications() {
  // Register the listener with MemoryMXBean
  NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
  emitter.addNotificationListener(listener, null, null);

  // set collection usage threshold.
  for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
    if (pool.getType() == MemoryType.HEAP &&
      pool.isUsageThresholdSupported() &&
      pool.isCollectionUsageThresholdSupported()) {

      long threshold = (pool.getUsage().getMax() * thresholdPercentage) / 100;
      logger.info("setting collection threshold for " + pool.getName() +
        " with max " + pool.getUsage().getMax() +
        " to " + threshold);

      pool.setCollectionUsageThreshold(threshold);
      monitoredPools.put(pool.getName(), pool.getCollectionUsageThresholdCount());
    } else {
      logger.info("skip monitoring for pool " + pool.getName());
    }
  }
}
 
Example 2
Source File: MonitorMemory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onConfigured(final ConfigurationContext config) throws InitializationException {
    final String desiredMemoryPoolName = config.getProperty(MEMORY_POOL_PROPERTY).getValue();
    final String thresholdValue = config.getProperty(THRESHOLD_PROPERTY).getValue().trim();
    threshold = thresholdValue;

    final Long reportingIntervalValue = config.getProperty(REPORTING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    if (reportingIntervalValue == null) {
        reportingIntervalMillis = config.getSchedulingPeriod(TimeUnit.MILLISECONDS);
    } else {
        reportingIntervalMillis = reportingIntervalValue;
    }

    final List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (int i = 0; i < memoryPoolBeans.size() && monitoredBean == null; i++) {
        MemoryPoolMXBean memoryPoolBean = memoryPoolBeans.get(i);
        String memoryPoolName = memoryPoolBean.getName();
        if (desiredMemoryPoolName.equals(memoryPoolName)) {
            monitoredBean = memoryPoolBean;
            if (memoryPoolBean.isCollectionUsageThresholdSupported()) {
                long calculatedThreshold;
                if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
                    calculatedThreshold = DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
                } else {
                    final String percentage = thresholdValue.substring(0, thresholdValue.length() - 1);
                    final double pct = Double.parseDouble(percentage) / 100D;
                    calculatedThreshold = (long) (monitoredBean.getUsage().getMax() * pct);
                }
                monitoredBean.setUsageThreshold(calculatedThreshold);
            }
        }
    }

    if (monitoredBean == null) {
        throw new InitializationException("Found no JVM Memory Pool with name " + desiredMemoryPoolName + "; will not monitor Memory Pool");
    }
}
 
Example 3
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Register with the JVM to get threshold events.
 * 
 * Package private for testing.
 */
void startJVMThresholdListener() {
  final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();

  // Set collection threshold to a low value, so that we can get
  // notifications after every GC run. After each such collection
  // threshold notification we set the usage thresholds to an
  // appropriate value.
  if (!testDisableMemoryUpdates) {
    memoryPoolMXBean.setCollectionUsageThreshold(1);
    // also set for notifications from survivor space GC
    final MemoryPoolMXBean survivorPoolMXBean = getSurvivorPoolMXBean();
    if (survivorPoolMXBean != null
        && survivorPoolMXBean.isCollectionUsageThresholdSupported()) {
      survivorPoolMXBean.setCollectionUsageThreshold(1);
    }
  }
  
  final long usageThreshold = memoryPoolMXBean.getUsageThreshold();
  this.cache.getLoggerI18n().info(
      LocalizedStrings.HeapMemoryMonitor_OVERRIDDING_MEMORYPOOLMXBEAN_HEAP_0_NAME_1,
      new Object[] { Long.valueOf(usageThreshold), memoryPoolMXBean.getName() });

  MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
  NotificationEmitter emitter = (NotificationEmitter) mbean;
  emitter.addNotificationListener(this, null, null);
}
 
Example 4
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Register with the JVM to get threshold events.
 * 
 * Package private for testing.
 */
void startJVMThresholdListener() {
  final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();

  // Set collection threshold to a low value, so that we can get
  // notifications after every GC run. After each such collection
  // threshold notification we set the usage thresholds to an
  // appropriate value.
  if (!testDisableMemoryUpdates) {
    memoryPoolMXBean.setCollectionUsageThreshold(1);
    // also set for notifications from survivor space GC
    final MemoryPoolMXBean survivorPoolMXBean = getSurvivorPoolMXBean();
    if (survivorPoolMXBean != null
        && survivorPoolMXBean.isCollectionUsageThresholdSupported()) {
      survivorPoolMXBean.setCollectionUsageThreshold(1);
    }
  }
  
  final long usageThreshold = memoryPoolMXBean.getUsageThreshold();
  this.cache.getLoggerI18n().info(
      LocalizedStrings.HeapMemoryMonitor_OVERRIDDING_MEMORYPOOLMXBEAN_HEAP_0_NAME_1,
      new Object[] { Long.valueOf(usageThreshold), memoryPoolMXBean.getName() });

  MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
  NotificationEmitter emitter = (NotificationEmitter) mbean;
  emitter.addNotificationListener(this, null, null);
}
 
Example 5
Source File: MonitorMemory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onConfigured(final ConfigurationContext config) throws InitializationException {
    final String desiredMemoryPoolName = config.getProperty(MEMORY_POOL_PROPERTY).getValue();
    final String thresholdValue = config.getProperty(THRESHOLD_PROPERTY).getValue().trim();
    threshold = thresholdValue;

    final Long reportingIntervalValue = config.getProperty(REPORTING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    if (reportingIntervalValue == null) {
        reportingIntervalMillis = config.getSchedulingPeriod(TimeUnit.MILLISECONDS);
    } else {
        reportingIntervalMillis = reportingIntervalValue;
    }

    final List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (int i = 0; i < memoryPoolBeans.size() && monitoredBean == null; i++) {
        MemoryPoolMXBean memoryPoolBean = memoryPoolBeans.get(i);
        String memoryPoolName = memoryPoolBean.getName();
        if (desiredMemoryPoolName.equals(memoryPoolName)) {
            monitoredBean = memoryPoolBean;
            if (memoryPoolBean.isCollectionUsageThresholdSupported()) {
                long calculatedThreshold;
                if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
                    calculatedThreshold = DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
                } else {
                    final String percentage = thresholdValue.substring(0, thresholdValue.length() - 1);
                    final double pct = Double.parseDouble(percentage) / 100D;
                    calculatedThreshold = (long) (monitoredBean.getUsage().getMax() * pct);
                }
                monitoredBean.setUsageThreshold(calculatedThreshold);
            }
        }
    }

    if (monitoredBean == null) {
        throw new InitializationException("Found no JVM Memory Pool with name " + desiredMemoryPoolName + "; will not monitor Memory Pool");
    }
}
 
Example 6
Source File: MXBeanInteropTest1.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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 7
Source File: MXBeanInteropTest1.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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 8
Source File: MXBeanInteropTest1.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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 9
Source File: VMLogger.java    From openjdk-systemtest with Apache License 2.0 4 votes vote down vote up
public void enableOptionalFunctionality()  {
    try {
        // ClassLoadingMXBean operations
        classBean.setVerbose(true);

        // MemoryMXBean operations
        memBean.setVerbose(true);

        // MemoryPoolMXBean operations
        for (MemoryPoolMXBean memPoolBean: memPoolBeans) {
            memPoolBean.resetPeakUsage();

            if (memPoolBean.isCollectionUsageThresholdSupported()) {
                memPoolBean.setCollectionUsageThreshold(10000);
            }

            if (memPoolBean.isUsageThresholdSupported()) {
                memPoolBean.setUsageThreshold(200000);
            }            
        }

        // ThreadMXBean operations
        threadBean.resetPeakThreadCount();

        if (threadBean.isThreadContentionMonitoringSupported()) {
            threadBean.setThreadContentionMonitoringEnabled(true);
        }

        if (threadBean.isThreadCpuTimeSupported()) {
            threadBean.setThreadCpuTimeEnabled(true);
        }
        
        // LoggingMXBean operations
        List<String> loggers = logBean.getLoggerNames();
        
        String[] levels = {"SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST"};
        int i = 0;
        
        for( String logger : loggers) {               	
            if (i > 6) {
            	i = i - 7;
            }
            
            // There's a chance the logger no longer exists
            String parent = logBean.getParentLoggerName(logger);
            if (parent != null) {
            	logBean.setLoggerLevel(logger, levels[i]);
            }
            
            i++;                
        }
        
    } catch (UnsupportedOperationException uoe) {
        Message.logOut("One of the operations you tried is not supported");
        uoe.printStackTrace();
    }
}
 
Example 10
Source File: MXBeanInteropTest1.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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 11
Source File: MXBeanInteropTest1.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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 12
Source File: MXBeanInteropTest1.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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 13
Source File: MXBeanInteropTest1.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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 ;
}