當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。