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


Java MemoryMXBean.gc方法代码示例

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


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

示例1: 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

示例2: 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

示例3: beforeEvent

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
@Override
public MonitorResult beforeEvent(MonitorResult previousResult, LoadControlCallback callback, EventMetadata metadata,
      String currentSetpointId) {
   if (previousResult == MonitorResult.SHED || status != MonitorStatus.ON) {
      return previousResult;
   }

   MemoryPoolMXBean tenurePool = VMLoadControlJMXBean.getTenuredGenPool();
   if (tenurePool == null) {
      return previousResult;
   }

   MonitorResult result = tryShed(tenurePool, callback, metadata, currentSetpointId);
   if (result == MonitorResult.PASSED) {
      result = tryValve(tenurePool, callback, metadata, currentSetpointId);
   }
   if (result == MonitorResult.PASSED) {
      result = tryUsageAlarm(tenurePool, callback, metadata, currentSetpointId);
   }
   if (result == MonitorResult.PASSED) {
      result = tryCollectionUsageAlarm(tenurePool, callback, metadata, currentSetpointId);
   }

   if (result == MonitorResult.SHED) {
      long now = System.currentTimeMillis();
      if (garbageCollectionWaitTime > 0 && !thresholdExceededTimestamp.compareAndSet(0, now)) {
         long ts = thresholdExceededTimestamp.get();
         if (ts != 0 && now - ts > garbageCollectionWaitTime) {
            thresholdExceededTimestamp.set(0);
            MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
            memoryBean.gc();
         }
      }
   }
   return result;
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:37,代码来源:MemoryMonitor.java

示例4: report

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private static void report(final String what) {
	MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
	memoryMXBean.gc();
	long used = memoryMXBean.getHeapMemoryUsage().getUsed();
	long delta = used - baseline;
	System.out.println(what + ": " + delta + " (total=" + used + "), " + (delta / count) + "/unit");
}
 
开发者ID:virgo47,项目名称:javasimon,代码行数:8,代码来源:SimonMemoryConsumption.java

示例5: setBaseLine

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private static void setBaseLine(final String what) {
	MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
	memoryMXBean.gc();
	memoryMXBean.gc();
	baseline = memoryMXBean.getHeapMemoryUsage().getUsed();
	System.out.println(what + ": " + baseline);
}
 
开发者ID:virgo47,项目名称:javasimon,代码行数:8,代码来源:SimonMemoryConsumption.java

示例6: checkMemory

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private static void checkMemory() {
  MemoryMXBean mBean = ManagementFactory.getMemoryMXBean();
  mBean.gc();
  LOG.info("Build " + buildCount + " current used memory: "
    + mBean.getHeapMemoryUsage().getUsed() + " bytes");
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:7,代码来源:BuildServer.java

示例7: reportAbsolute

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private static void reportAbsolute(final String what) {
	MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
	memoryMXBean.gc();
	memoryMXBean.gc();
	System.out.println(what + ": " + memoryMXBean.getHeapMemoryUsage().getUsed());
}
 
开发者ID:virgo47,项目名称:javasimon,代码行数:7,代码来源:SimonMemoryConsumption.java


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