Java Code Examples for java.lang.management.MemoryPoolMXBean#isUsageThresholdSupported()
The following examples show how to use
java.lang.management.MemoryPoolMXBean#isUsageThresholdSupported() .
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: PerformanceWatcher.java From consulo with Apache License 2.0 | 6 votes |
private void watchCodeCache(final MemoryPoolMXBean bean) { final long threshold = bean.getUsage().getMax() - 5 * 1024 * 1024; if (!bean.isUsageThresholdSupported() || threshold <= 0) return; bean.setUsageThreshold(threshold); final NotificationEmitter emitter = (NotificationEmitter)ManagementFactory.getMemoryMXBean(); emitter.addNotificationListener(new NotificationListener() { @Override public void handleNotification(Notification n, Object hb) { if (bean.getUsage().getUsed() > threshold) { LOG.info("Code Cache is almost full"); dumpThreads("codeCacheFull", true); try { emitter.removeNotificationListener(this); } catch (ListenerNotFoundException e) { LOG.error(e); } } } }, null, null); }
Example 2
Source File: MemoryWatchdog.java From pitest with Apache License 2.0 | 6 votes |
public static void addWatchDogToAllPools(final long threshold, final NotificationListener listener) { final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); final NotificationEmitter ne = (NotificationEmitter) memBean; ne.addNotificationListener(listener, null, null); final List<MemoryPoolMXBean> memPools = ManagementFactory .getMemoryPoolMXBeans(); for (final MemoryPoolMXBean mp : memPools) { if (mp.isUsageThresholdSupported()) { final MemoryUsage mu = mp.getUsage(); final long max = mu.getMax(); final long alert = (max * threshold) / 100; // LOG.info("Setting a threshold shutdown on pool: " + mp.getName() // + " for: " + alert); mp.setUsageThreshold(alert); } } }
Example 3
Source File: HeapMonitorThread.java From dremio-oss with Apache License 2.0 | 6 votes |
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 4
Source File: MemoryWarningSystem.java From metafacture-core with Apache License 2.0 | 5 votes |
/** * Tenured Space Pool can be determined by it being of type HEAP and by it * being possible to set the usage threshold. * * @return MXBean for the Tenured Space Pool */ private static MemoryPoolMXBean findTenuredGenPool() { // I don't know whether this approach is better, or whether // we should rather check for the pool name "Tenured Gen"? for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { return pool; } throw new AssertionError("Could not find tenured space"); }
Example 5
Source File: MemoryWarningService.java From maven-framework-project with MIT License | 5 votes |
/** * Tenured Space Pool can be determined by it being of type HEAP and by it * being possible to set the usage threshold. */ private static MemoryPoolMXBean findTenuredGenPool() { for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { // I don't know whether this approach is better, or whether // we should rather check for the pool name "Tenured Gen"? if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { return pool; } } throw new AssertionError("Could not find tenured space"); }
Example 6
Source File: MemoryMonitor.java From rice with Educational Community License v2.0 | 5 votes |
private static MemoryPoolMXBean findTenuredGenPool() { for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { return pool; } } throw new AssertionError("could not find tenured space"); }
Example 7
Source File: MemoryMonitor.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
public static void setPercentageUsageThreshold(double percentage) { for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { if (percentage <= 0.0 || percentage > 1.0) { throw new IllegalArgumentException("percentage not in range"); } long warningThreshold = (long) (pool.getUsage().getMax() * percentage); pool.setUsageThreshold(warningThreshold); } } }
Example 8
Source File: MXBeanInteropTest1.java From jdk8u_jdk with GNU General Public License v2.0 | 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 9
Source File: SpillableMemoryManager.java From spork with Apache License 2.0 | 4 votes |
private SpillableMemoryManager() { ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null); List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans(); MemoryPoolMXBean tenuredHeap = null; long tenuredHeapSize = 0; 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; // CMS Old Gen or "tenured" is the only heap that supports // setting usage threshold. if (pool.isUsageThresholdSupported()) { tenuredHeapSize = size; tenuredHeap = pool; } } } extraGCSpillSizeThreshold = (long) (totalSize * extraGCThresholdFraction); if (tenuredHeap == null) { throw new RuntimeException("Couldn't find heap"); } log.debug("Selected heap to monitor (" + tenuredHeap.getName() + ")"); // we want to set both collection and usage threshold alerts to be // safe. In some local tests after a point only collection threshold // notifications were being sent though usage threshold notifications // were sent early on. So using both would ensure that // 1) we get notified early (though usage threshold exceeded notifications) // 2) we get notified always when threshold is exceeded (either usage or // collection) /* We set the threshold to be 50% of tenured since that is where * the GC starts to dominate CPU time according to Sun doc */ tenuredHeap.setCollectionUsageThreshold((long)(tenuredHeapSize * collectionMemoryThresholdFraction)); // we set a higher threshold for usage threshold exceeded notification // since this is more likely to be effective sooner and we do not // want to be spilling too soon tenuredHeap.setUsageThreshold((long)(tenuredHeapSize * memoryThresholdFraction)); }
Example 10
Source File: Fawe.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
private void setupMemoryListener() { if (Settings.IMP.MAX_MEMORY_PERCENT < 1 || Settings.IMP.MAX_MEMORY_PERCENT > 99) { return; } try { final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); final NotificationEmitter ne = (NotificationEmitter) memBean; ne.addNotificationListener(new NotificationListener() { @Override public void handleNotification(final Notification notification, final Object handback) { final long heapSize = Runtime.getRuntime().totalMemory(); final long heapMaxSize = Runtime.getRuntime().maxMemory(); if (heapSize < heapMaxSize) { return; } MemUtil.memoryLimitedTask(); } }, null, null); final List<MemoryPoolMXBean> memPools = ManagementFactory.getMemoryPoolMXBeans(); for (final MemoryPoolMXBean mp : memPools) { if (mp.isUsageThresholdSupported()) { final MemoryUsage mu = mp.getUsage(); final long max = mu.getMax(); if (max < 0) { continue; } final long alert = (max * Settings.IMP.MAX_MEMORY_PERCENT) / 100; mp.setUsageThreshold(alert); } } } catch (Throwable e) { debug("====== MEMORY LISTENER ERROR ======"); MainUtil.handleError(e, false); debug("==================================="); debug("FAWE needs access to the JVM memory system:"); debug(" - Change your Java security settings"); debug(" - Disable this with `max-memory-percent: -1`"); debug("==================================="); } }
Example 11
Source File: MXBeanInteropTest1.java From dragonwell8_jdk with GNU General Public License v2.0 | 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 12
Source File: MXBeanInteropTest1.java From jdk8u-jdk with GNU General Public License v2.0 | 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 13
Source File: MXBeanInteropTest1.java From openjdk-jdk9 with GNU General Public License v2.0 | 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 14
Source File: MXBeanInteropTest1.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 15
Source File: VMLogger.java From openjdk-systemtest with Apache License 2.0 | 4 votes |
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 16
Source File: MXBeanInteropTest1.java From openjdk-jdk8u with GNU General Public License v2.0 | 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 17
Source File: MXBeanInteropTest1.java From TencentKona-8 with GNU General Public License v2.0 | 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 ; }