当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactory.getMemoryMXBean方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.getMemoryMXBean方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getMemoryMXBean方法的具体用法?Java ManagementFactory.getMemoryMXBean怎么用?Java ManagementFactory.getMemoryMXBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getMemoryMXBean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public String call() {
  Map<String, String> memoryMap = new HashMap<>();
  OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
  double cpu = osMxBean.getSystemLoadAverage();
  memoryMap.put("cpuLoad", String.format(doubleStringFormatter, round(cpu, doubleRoundPlaces)));

  ThreadMXBean threadmxBean = ManagementFactory.getThreadMXBean();
  int threadCount = threadmxBean.getThreadCount();
  memoryMap.put("cpuRunningThreads", String.valueOf(threadCount));

  MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
  MemoryUsage memHeapUsage = memBean.getHeapMemoryUsage();
  MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage();
  memoryMap.put("heapInit", String.valueOf(memHeapUsage.getInit()));
  memoryMap.put("heapMax", String.valueOf(memHeapUsage.getMax()));
  memoryMap.put("heapCommit", String.valueOf(memHeapUsage.getCommitted()));
  memoryMap.put("heapUsed", String.valueOf(memHeapUsage.getUsed()));
  memoryMap.put("nonHeapInit", String.valueOf(nonHeapUsage.getInit()));
  memoryMap.put("nonHeapMax", String.valueOf(nonHeapUsage.getMax()));
  memoryMap.put("nonHeapCommit", String.valueOf(nonHeapUsage.getCommitted()));
  memoryMap.put("nonHeapUsed", String.valueOf(nonHeapUsage.getUsed()));
  return memoryMap.toString();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:MetricsServoRegistry.java

示例2: createNotification

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
static void createNotification(String notifType,
                               String poolName,
                               MemoryUsage usage,
                               long count) {
    MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
    if (!mbean.hasListeners()) {
        // if no listener is registered.
        return;
    }
    long timestamp = System.currentTimeMillis();
    String msg = getNotifMsg(notifType);
    Notification notif = new Notification(notifType,
                                          mbean.getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          msg);
    MemoryNotificationInfo info =
        new MemoryNotificationInfo(poolName,
                                   usage,
                                   count);
    CompositeData cd =
        MemoryNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    mbean.sendNotification(notif);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:MemoryImpl.java

示例3: envi

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public String envi() {
    Map<String, String> result = new HashMap<String, String>();
    // 系统信息
    result.put(RegistryMonitorConstants.OSNAME, System.getProperty(RegistryMonitorConstants.OSNAME, "not specified"));
    result.put(RegistryMonitorConstants.JAVA_VERSION, System.getProperty(RegistryMonitorConstants.JAVA_VERSION, "not specified"));
    result.put(RegistryMonitorConstants.JDK_PATH, System.getProperty(RegistryMonitorConstants.JDK_PATH, "not specified"));
    result.put(RegistryMonitorConstants.APP_PATH, System.getProperty(RegistryMonitorConstants.APP_PATH, "not specified"));

    // jvm信息
    MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean();
    MemoryUsage usage = memorymbean.getHeapMemoryUsage();
    result.put(RegistryMonitorConstants.JVM_INIT, String.valueOf(usage.getInit()));
    result.put(RegistryMonitorConstants.JVM_MAX, String.valueOf(usage.getMax()));
    result.put(RegistryMonitorConstants.JVM_USED, String.valueOf(usage.getUsed()));
    
    //线程信息
    ThreadMXBean tm = (ThreadMXBean) ManagementFactory.getThreadMXBean();
    result.put(RegistryMonitorConstants.JVM_THREAD_COUNT, String.valueOf(tm.getThreadCount()));
    result.put(RegistryMonitorConstants.JVM_PEAKTHREAD_COUNT, String.valueOf(tm.getPeakThreadCount()));
    result.put(RegistryMonitorConstants.JVM_CURRENTTHREAD_CPUTIME, String.valueOf(tm.getCurrentThreadCpuTime()));
    result.put(RegistryMonitorConstants.JVM_CURRENTTHREAD_USERTIME, String.valueOf(tm.getCurrentThreadUserTime()));
    return JSON.toJSONString(result);
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:25,代码来源:RegistryStatusServiceImpl.java

示例4: startJVMThresholdListener

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * 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);
  }

  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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:HeapMemoryMonitor.java

示例5: sense

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void sense(final MetricRecorder.Context metricContext)
{
    MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();

    reportHeapUsage(mxBean, metricContext);
    reportNonHeapUsage(mxBean, metricContext);
}
 
开发者ID:awslabs,项目名称:swage,代码行数:9,代码来源:MemorySensor.java

示例6: Datum

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Constructor accepts some system values and generates some Java values.
 *
 * @param rss Resident set size.
 */
Datum(long rss) {
    MemoryMXBean mmxb = ManagementFactory.getMemoryMXBean();
    MemoryUsage muheap = mmxb.getHeapMemoryUsage();
    MemoryUsage musys = mmxb.getNonHeapMemoryUsage();

    timestamp = System.currentTimeMillis();
    this.rss = rss;
    javatotalheapmem = muheap.getCommitted();
    javausedheapmem = muheap.getUsed();
    javatotalsysmem = musys.getCommitted();
    javausedsysmem = musys.getUsed();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:18,代码来源:SystemStatsCollector.java

示例7: run

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public void run() {
	bContinue = true;
	
	try {
		while (bContinue) {
	        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
	        MemoryUsage memoryUsageHeap = memoryMXBean.getHeapMemoryUsage(); 
	        MemoryUsage memoryUsageNonHeap = memoryMXBean.getNonHeapMemoryUsage();
	        
	        setUsageCounter("[Memory] Heap memory usage", memoryUsageHeap);
	        setUsageCounter("[Memory] Non heap memory usage", memoryUsageNonHeap);
	        setUsageCounter("[Memory] Total used", (memoryUsageHeap.getUsed() + memoryUsageNonHeap.getUsed()) / 1024 + "K");
	        
			synchronized (usageCounters) {
				List<String> ls = new ArrayList<String>();
				ls.addAll(usageCounters.keySet());
				Collections.sort(ls);
				for (String counter : ls) {
					Engine.logUsageMonitor.info(counter + ": " + usageCounters.get(counter));
				}
			}
		
			Thread.sleep(30000);
		}
	} catch (NullPointerException npe) {
		if (Engine.theApp == null) {
			// Engine.theApp == null probably means the engine is getting stopped
			// so gracefully ignore and exit thread
			return;
		}
		else {
			npe.printStackTrace();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

	usageCounters = null;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:40,代码来源:UsageMonitor.java

示例8: SystemManager

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public SystemManager(){
  memoryBean = ManagementFactory.getMemoryMXBean();
  BufferPoolMXBean localBean = null;
  List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
  for(BufferPoolMXBean b : pools){
    if(b.getName().equals("direct")){
      localBean = b;

    }
  }
  directBean = localBean;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:13,代码来源:DrillTest.java

示例9: telnet

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
   public String telnet(Channel channel, String message) {
	StringBuilder sb = new StringBuilder();
	//内存使用情况
       MemoryMXBean mmxb = ManagementFactory.getMemoryMXBean();
       long max = mmxb.getHeapMemoryUsage().getMax();
       long used = mmxb.getHeapMemoryUsage().getUsed();
       long init = mmxb.getHeapMemoryUsage().getInit();
       long commit = mmxb.getHeapMemoryUsage().getCommitted();
       sb.append("********Memory status******************").append(line);
       sb.append("Max JVM Heap Memory:").append(max / 1024 / 1024).append("M").append(line)
               .append("Used Heap Memory:").append(used / 1024 / 1024).append("M").append(line)
               .append("Init Heap Memory:").append(init / 1024 / 1024).append("M").append(line)
               .append("Commited Heap Memory:").append(commit/1024/1024).append("M").append(line);
       
       sb.append("********Thread status********************").append(line);
       //线程数
       ThreadMXBean txmb = ManagementFactory.getThreadMXBean();
       sb.append("Peak thread count:").append(txmb.getPeakThreadCount()).append("").append(line)
               .append("Thread count:").append(txmb.getThreadCount()).append("").append(line);

       sb.append("********Runtime status******************").append(line);
       //启动入口参数
       RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
       sb.append("InputArguments:[");
       for(String ia : rmxb.getInputArguments()){
       	sb.append(ia).append(",");
       }
       sb.deleteCharAt(sb.length()-1).append("]").append(line);
       sb.append("JVM start time:").append(DateUtils.dateToStr(new Date(rmxb.getStartTime()))).append(line);
       
       return sb.toString();
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:34,代码来源:JVMStatusTelnetHandler.java

示例10: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    System.out.println(">>>>> Memory");
    MemoryMXBean memoryMBean = ManagementFactory.getMemoryMXBean();
    System.out.println("Heap memory usage: " + memoryMBean.getHeapMemoryUsage());
    System.out.println("Non-Heap memory usage: " + memoryMBean.getNonHeapMemoryUsage());
    System.out.println("Objects pending finalization: " + memoryMBean.getObjectPendingFinalizationCount());

    System.out.println(">>>>> GC");
    ManagementFactory.getGarbageCollectorMXBeans().stream().forEach(bean -> {
        GarbageCollectorMXBean gcBean = (GarbageCollectorMXBean) bean;
        ((NotificationEmitter) gcBean).addNotificationListener(new GCLogger(), null, null);

        System.out.println(">> " + gcBean.getName());
        System.out.println("Collection count: " + gcBean.getCollectionCount());
        System.out.println("Collection time: " + gcBean.getCollectionTime());
        System.out.println("Last GC: " + gcBean.getLastGcInfo());
    });

    System.out.println(">>>>> Memory pool mbeans");
    ManagementFactory.getMemoryPoolMXBeans().stream().forEach(bean -> {
        System.out.println(">> " + bean.getName() + " " + bean.getType());
        System.out.println("Collection usage: " + bean.getCollectionUsage());
        System.out.println("Peak usage: " + bean.getPeakUsage());
        System.out.println("Usage: " + bean.getUsage());
        System.out.println("Memory manager names: " + Arrays.toString(bean.getMemoryManagerNames()));
    });


    while (true) {
        System.out.println("Allocating 1Mb");
        byte[] allocation = new byte[1024 * 1024];
        Thread.sleep(100);
    }
}
 
开发者ID:kslisenko,项目名称:java-performance,代码行数:35,代码来源:MemoryAndGC.java

示例11: doMemoryUpdates

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void doMemoryUpdates() {
    MemoryMXBean memoryMXBean =
           ManagementFactory.getMemoryMXBean();
    MemoryUsage memNonHeap =
            memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap =
            memoryMXBean.getHeapMemoryUsage();
    Runtime runtime = Runtime.getRuntime();

    metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed()/M);
    metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted()/M);
    metrics.setMetric("memHeapUsedM", memHeap.getUsed()/M);
    metrics.setMetric("memHeapCommittedM", memHeap.getCommitted()/M);
    metrics.setMetric("maxMemoryM", runtime.maxMemory()/M);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:JvmMetrics.java

示例12: registerMemoryStatistics

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void registerMemoryStatistics() {
	final MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
	registry.set("jvm.Memory.Heap", "used", (Gauge) () -> mem.getHeapMemoryUsage().getUsed());
	registry.set("jvm.Memory.Heap", "init", (Gauge) () -> mem.getHeapMemoryUsage().getInit());
	registry.set("jvm.Memory.Heap", "max", (Gauge) () -> mem.getHeapMemoryUsage().getMax());
	registry.set("jvm.Memory.Heap", "comitted", (Gauge) () -> mem.getHeapMemoryUsage().getCommitted());
	registry.set("jvm.Memory.NonHeap", "used", (Gauge) () -> mem.getNonHeapMemoryUsage().getUsed());
	registry.set("jvm.Memory.NonHeap", "init", (Gauge) () -> mem.getNonHeapMemoryUsage().getInit());
	registry.set("jvm.Memory.NonHeap", "max", (Gauge) () -> mem.getNonHeapMemoryUsage().getMax());
	registry.set("jvm.Memory.NonHeap", "comitted", (Gauge) () -> mem.getNonHeapMemoryUsage().getCommitted());
}
 
开发者ID:mevdschee,项目名称:tqdev-metrics,代码行数:12,代码来源:SystemMonitor.java

示例13: DefaultSystemMonitor

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public DefaultSystemMonitor() {
  this(ManagementFactory.getOperatingSystemMXBean(), ManagementFactory.getThreadMXBean(),
      ManagementFactory.getMemoryMXBean());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:5,代码来源:DefaultSystemMonitor.java

示例14: logParams

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private String logParams() {
        StringBuilder sb = new StringBuilder(500);
        sb.append("Diagnostic information\n");
        try {
            RuntimeMXBean         rmBean     = ManagementFactory.getRuntimeMXBean();
            CompilationMXBean     cmpMBean   = ManagementFactory.getCompilationMXBean();
//            ThreadMXBean          tmBean     = ManagementFactory.getThreadMXBean();
            MemoryMXBean          memoryBean = ManagementFactory.getMemoryMXBean();
            ClassLoadingMXBean    clMBean    = ManagementFactory.getClassLoadingMXBean();

//            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
//            ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic");
//            com.sun.management.OperatingSystemMXBean sunOSMBean  =
//               ManagementFactory.getSunOperatingSystemMXBean();

//            Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties());
//            System.out.println("System properties");
//            for (Map.Entry<String, String> entry: props.entrySet()) {
//                System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue());
//            }
            sb.append("Input arguments:");
            for (String s: rmBean.getInputArguments()) {
                sb.append("\n\t").append(s);
            }
            
            if (cmpMBean != null) {
                sb.append("\nCompiler: "+cmpMBean.getName()).append('\n');
            }
            
            // Memory
            MemoryUsage usage = memoryBean.getHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Heap memory");
            usage = memoryBean.getNonHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Non heap memory");
            for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) {
                sb.append("Garbage collector: ").append(gcMBean.getName())
                        .append(" (Collections=").append(gcMBean.getCollectionCount())
                        .append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime()))
                        .append(")\n");
            }
            
            // classes
            int clsLoaded;
            long clsTotal, clsUnloaded;
            clsLoaded = clMBean.getLoadedClassCount();
            clsTotal = clMBean.getTotalLoadedClassCount();
            clsUnloaded = clMBean.getUnloadedClassCount();
            sb.append("Classes: loaded=").append(clsLoaded)
                    .append(" total loaded=").append(clsTotal)
                    .append(" unloaded ").append(clsUnloaded).append('\n');

//        } catch (MalformedObjectNameException ex) {
//            Logger.getLogger("global").log(Level.WARNING, null, ex);
        } catch (NullPointerException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
        return sb.toString();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:DiagnosticTask.java

示例15: getMemoryMxBean

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
MemoryMXBean getMemoryMxBean() {
  return ManagementFactory.getMemoryMXBean();
}
 
开发者ID:SAP,项目名称:java-memory-assistant,代码行数:4,代码来源:MBeanMonitor.java


注:本文中的java.lang.management.ManagementFactory.getMemoryMXBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。