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


Java MemoryMXBean类代码示例

本文整理汇总了Java中java.lang.management.MemoryMXBean的典型用法代码示例。如果您正苦于以下问题:Java MemoryMXBean类的具体用法?Java MemoryMXBean怎么用?Java MemoryMXBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: call

import java.lang.management.MemoryMXBean; //导入依赖的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: logSystemInfo

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
public static void logSystemInfo() {
    try {
        OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
        Log.info("Operating system"
                + " name: " + operatingSystemBean.getName()
                + " version: " + operatingSystemBean.getVersion()
                + " architecture: " + operatingSystemBean.getArch());

        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        Log.info("Java runtime"
                + " name: " + runtimeBean.getVmName()
                + " vendor: " + runtimeBean.getVmVendor()
                + " version: " + runtimeBean.getVmVersion());

        MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
        Log.info("Memory limit"
                + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"
                + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");

        Log.info("Character encoding: "
                + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());

    } catch (Exception error) {
        Log.warning("Failed to get system info");
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:27,代码来源:Log.java

示例3: startJVMThresholdListener

import java.lang.management.MemoryMXBean; //导入依赖的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

示例4: envi

import java.lang.management.MemoryMXBean; //导入依赖的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

示例5: getMaxMemory

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
private static long getMaxMemory()
{
  try {
    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = null;
    
    if (memoryBean != null) {
      heap = memoryBean.getHeapMemoryUsage();
    }
    
    if (heap != null) {
      return Math.max(heap.getMax(), heap.getCommitted());
    }
    else {
      Runtime runtime = Runtime.getRuntime();
      
      return Math.max(runtime.maxMemory(), runtime.totalMemory());
    }
  } catch (Exception e) {
    e.printStackTrace();
  }

  return Runtime.getRuntime().maxMemory();
}
 
开发者ID:baratine,项目名称:baratine,代码行数:25,代码来源:KelpManagerBuilder.java

示例6: monitorMemory

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
public String monitorMemory() {
	StringBuilder sb = new StringBuilder("Memory:");
	MemoryMXBean mmbean = ManagementFactory.getMemoryMXBean();
	MemoryUsage hmu = mmbean.getHeapMemoryUsage();
	sb.append("[HeapMemoryUsage:");
	sb.append(" Used=" + formatBytes(hmu.getUsed() * 8));
	sb.append(" Committed=" + formatBytes(hmu.getCommitted() * 8));
	sb.append("]");

	MemoryUsage nhmu = mmbean.getNonHeapMemoryUsage();
	sb.append("[NonHeapMemoryUsage:");
	sb.append(" Used=" + formatBytes(nhmu.getUsed() * 8));
	sb.append(" Committed=" + formatBytes(nhmu.getCommitted() * 8));
	sb.append("]");
	return sb.toString();
}
 
开发者ID:blusechen,项目名称:venus,代码行数:17,代码来源:VMMonitor.java

示例7: doGet

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
/**
 * Renders tools page.
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Bundle[] bundles = BundleContextHolder.INSTANCE.getBundleContext().getBundles();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    TemplateEngine.getInstance().render(TemplateContext.builder()
            .request(req)
            .response(resp)
            .template(TOOLS_TEMPLATE)
            .locale(req.getLocale())
            .contextObject(ContextObject.newContextObject()
                    .put("username", req.getRemoteUser())
                    .put("sysProps", System.getProperties().entrySet())
                    .put("totalBundles", bundles.length)
                    .put("bundles", bundles)
                    .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")")
                    .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")")
                    .put("startTime", new Date(runtimeMXBean.getStartTime()))
                    .put("upTime", TimeUnit.MILLISECONDS.toMinutes(runtimeMXBean.getUptime()))
                    .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getMax()))
                    .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getUsed()))
                    .put("processors", Runtime.getRuntime().availableProcessors()))
            .build());
}
 
开发者ID:AdeptJ,项目名称:adeptj-runtime,代码行数:28,代码来源:ToolsServlet.java

示例8: main

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
public static void main(String[] args)
{
  MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
  System.out.println("Bean: " + bean);
  System.out.println("Heap memory usage: "
                     + bean.getHeapMemoryUsage());
  System.out.println("Non-heap memory usage: "
                     + bean.getNonHeapMemoryUsage());
  System.out.println("Objects pending finalization: "
                     + bean.getObjectPendingFinalizationCount());
  System.out.println("Running garbage collector via bean...");
  bean.gc();
  System.out.println("Heap memory usage: "
                     + bean.getHeapMemoryUsage());
  System.out.println("Non-heap memory usage: "
                     + bean.getNonHeapMemoryUsage());
  System.out.println("Objects pending finalization: "
                     + bean.getObjectPendingFinalizationCount());
  boolean verbosity = bean.isVerbose();
  System.out.println("Verbose memory output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  bean.setVerbose(!verbosity);
  System.out.println("Verbose memory output: " + (bean.isVerbose() ? "yes" : "no"));
}
 
开发者ID:vilie,项目名称:javify,代码行数:25,代码来源:TestMemory.java

示例9: getMemoryUsageStatsAsString

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
/**
 * Gets the memory footprint of the JVM in a string representation.
 *
 * @return A string describing how much heap memory and direct memory are allocated and used.
 */
public static String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
	MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
	MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

	long heapUsed = heap.getUsed() >> 20;
	long heapCommitted = heap.getCommitted() >> 20;
	long heapMax = heap.getMax() >> 20;

	long nonHeapUsed = nonHeap.getUsed() >> 20;
	long nonHeapCommitted = nonHeap.getCommitted() >> 20;
	long nonHeapMax = nonHeap.getMax() >> 20;

	return String.format("Memory usage stats: [HEAP: %d/%d/%d MB, " +
			"NON HEAP: %d/%d/%d MB (used/committed/max)]",
			heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:MemoryLogger.java

示例10: ClusterStatus

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
/**
 * @param numDecommissionedNodes number of decommission trackers
 */
ClusterStatus(int trackers, int blacklists, long ttExpiryInterval, 
              int maps, int reduces, int maxMaps, int maxReduces, 
              JobTracker.State state, int numDecommissionedNodes) {
  numActiveTrackers = trackers;
  numBlacklistedTrackers = blacklists;
  this.numExcludedNodes = numDecommissionedNodes;
  this.ttExpiryInterval = ttExpiryInterval;
  map_tasks = maps;
  reduce_tasks = reduces;
  max_map_tasks = maxMaps;
  max_reduce_tasks = maxReduces;
  this.state = state;

  MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
  MemoryUsage status = memoryMXBean.getHeapMemoryUsage();
  used_memory = status.getUsed();
  max_memory = status.getMax();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:22,代码来源:ClusterStatus.java

示例11: MemoryMonitor

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
public MemoryMonitor() {
    LOG.info("initializing");
    this.springContextId = "Unknown";
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(new NotificationListener() {
        public void handleNotification(Notification n, Object hb) {
            if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                long maxMemory = tenuredGenPool.getUsage().getMax();
                long usedMemory = tenuredGenPool.getUsage().getUsed();
                for (Listener listener : listeners) {
                    listener.memoryUsageLow(springContextId, usedMemory, maxMemory);
                }
            }
        }
    }, null, null);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:18,代码来源:MemoryMonitor.java

示例12: main

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
public static void main(String[] args)
{
  MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
  System.out.println("Bean: " + bean);
  System.out.println("Heap memory usage: " 
       + bean.getHeapMemoryUsage());
  System.out.println("Non-heap memory usage: " 
       + bean.getNonHeapMemoryUsage());
  System.out.println("Objects pending finalization: " 
       + bean.getObjectPendingFinalizationCount());
  System.out.println("Running garbage collector via bean...");
  bean.gc();
  System.out.println("Heap memory usage: " 
       + bean.getHeapMemoryUsage());
  System.out.println("Non-heap memory usage: " 
       + bean.getNonHeapMemoryUsage());
  System.out.println("Objects pending finalization: " 
       + bean.getObjectPendingFinalizationCount());
  boolean verbosity = bean.isVerbose();
  System.out.println("Verbose memory output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  bean.setVerbose(!verbosity);
  System.out.println("Verbose memory output: " + (bean.isVerbose() ? "yes" : "no"));
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:25,代码来源:TestMemory.java

示例13: memory

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
private void memory(Renderer renderer) {
  System.gc();
  MemoryMXBean mxbean = ManagementFactory.getMemoryMXBean();
  {
    long total = 0;
    for (int i = 0; i < 1000000; i++) {
      long start = mxbean.getHeapMemoryUsage().getUsed();
      renderer.render(text, entitiesList.get(i % 1000));
      long end = mxbean.getHeapMemoryUsage().getUsed();
      long diff = end - start;
      if (diff > 0) {
        total += diff;
      }
    }
    System.out.println("Memory: " + renderer.getClass().getSimpleName() + ": " + total / 1000000 + " bytes/op");
  }

}
 
开发者ID:spullara,项目名称:interviewcode,代码行数:19,代码来源:RendererBenchmarkTest.java

示例14: memoryUsage

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
private MemoryUsage memoryUsage() {
    MemoryUsage usage = new MemoryUsage();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    java.lang.management.MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    usage.heapInit = heapMemoryUsage.getInit();
    usage.heapUsed = heapMemoryUsage.getUsed();
    usage.heapCommitted = heapMemoryUsage.getCommitted();
    usage.heapMax = heapMemoryUsage.getMax();

    java.lang.management.MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
    usage.nonHeapInit = nonHeapMemoryUsage.getInit();
    usage.nonHeapUsed = nonHeapMemoryUsage.getUsed();
    usage.nonHeapCommitted = nonHeapMemoryUsage.getCommitted();
    usage.nonHeapMax = nonHeapMemoryUsage.getMax();

    return usage;
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:18,代码来源:MemoryUsageController.java

示例15: MemoryTileCache

import java.lang.management.MemoryMXBean; //导入依赖的package包/类
public MemoryTileCache() {
	log = Logger.getLogger(this.getClass());
	hashtable = new Hashtable<String, CacheEntry>(cacheSize);
	lruTiles = new CacheLinkedListElement();
	
	cacheSize = 500;
	MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
	NotificationBroadcaster emitter = (NotificationBroadcaster) mbean;
	emitter.addNotificationListener(this, null, null);
	// Set-up each memory pool to notify if the free memory falls below 10%
	for (MemoryPoolMXBean memPool : ManagementFactory.getMemoryPoolMXBeans()) {
		if (memPool.isUsageThresholdSupported()) {
			MemoryUsage memUsage = memPool.getUsage();
			memPool.setUsageThreshold((long) (memUsage.getMax() * 0.95));
		}
	}
}
 
开发者ID:bh4017,项目名称:mobac,代码行数:18,代码来源:MemoryTileCache.java


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