當前位置: 首頁>>代碼示例>>Java>>正文


Java GarbageCollectorMXBean類代碼示例

本文整理匯總了Java中java.lang.management.GarbageCollectorMXBean的典型用法代碼示例。如果您正苦於以下問題:Java GarbageCollectorMXBean類的具體用法?Java GarbageCollectorMXBean怎麽用?Java GarbageCollectorMXBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GarbageCollectorMXBean類屬於java.lang.management包,在下文中一共展示了GarbageCollectorMXBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
@Override
public void run() {
    List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
        @Override
        public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
            return mbean.getName().equals(garbageCollector);
        }
    });

    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        String pool = memoryPoolMXBean.getName();
        if (memoryPools.contains(pool)) {
            GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
            events.get(pool).slideAndInsert(event);
        }
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:GarbageCollectionCheck.java

示例2: sense

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
@Override
public void sense(final MetricRecorder.Context metricContext)
{
    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();

    // sum up metrics for all the garbage collectors
    //TODO: individual metrics per gc?
    long totalCollections = 0L;
    long totalTime = 0L;
    for (GarbageCollectorMXBean mxBean : gcBeans) {
        totalCollections += mxBean.getCollectionCount();
        totalTime += mxBean.getCollectionTime();
    }

    metricContext.record(COLLECTION_COUNT_TOTAL, totalCollections, Unit.NONE);
    metricContext.record(COLLECTION_TIME_TOTAL, totalTime, Unit.MILLISECOND);

    metricContext.record(COLLECTION_COUNT, (totalCollections - prevTotalCollections), Unit.NONE);
    metricContext.record(COLLECTION_TIME, (totalTime - prevTotalTime), Unit.MILLISECOND);

    prevTotalCollections = totalCollections;
    prevTotalTime = totalTime;
}
 
開發者ID:awslabs,項目名稱:swage,代碼行數:24,代碼來源:GarbageCollectorSensor.java

示例3: getGcUsage

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThresholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:24,代碼來源:JvmMetrics.java

示例4: printGCStats

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
public static void printGCStats() {
    long totalGarbageCollections = 0;
    long garbageCollectionTime = 0;

    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {

        long count = gc.getCollectionCount();

        if (count >= 0) {
            totalGarbageCollections += count;
        }

        long time = gc.getCollectionTime();

        if (time >= 0) {
            garbageCollectionTime += time;
        }
    }

    System.out.println("Total Garbage Collections: " + totalGarbageCollections);
    System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime);
}
 
開發者ID:nfisher,項目名稱:cljbuck,代碼行數:23,代碼來源:Main.java

示例5: printGCStats

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
public static void printGCStats(Tracer logger) {
    long totalGarbageCollections = 0;
    long garbageCollectionTime = 0;

    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {

        long count = gc.getCollectionCount();

        if (count >= 0) {
            totalGarbageCollections += count;
        }

        long time = gc.getCollectionTime();

        if (time >= 0) {
            garbageCollectionTime += time;
        }
    }

    logger.info("Total Garbage Collections: " + totalGarbageCollections);
    logger.info("Total Garbage Collection Time (ms): " + garbageCollectionTime);
}
 
開發者ID:nfisher,項目名稱:cljbuck,代碼行數:23,代碼來源:Main.java

示例6: installGCMonitoring

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
private static void installGCMonitoring() {
    List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gcbean : gcbeans) {
        NotificationEmitter emitter = (NotificationEmitter) gcbean;
        System.out.println(gcbean.getName());

        NotificationListener listener = (notification, handback) -> {
            if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());

                long duration = info.getGcInfo().getDuration();
                String gctype = info.getGcAction();

                System.out.println(gctype + ": - "
                        + info.getGcInfo().getId() + ", "
                        + info.getGcName()
                        + " (from " + info.getGcCause() + ") " + duration + " milliseconds");

            }
        };

        emitter.addNotificationListener(listener, null, null);
    }
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:25,代碼來源:Main.java

示例7: GcInfoBuilder

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
GcInfoBuilder(GarbageCollectorMXBean gc, String[] poolNames) {
    this.gc = gc;
    this.poolNames = poolNames;
    this.gcExtItemCount = getNumGcExtAttributes(gc);
    this.gcExtItemNames = new String[gcExtItemCount];
    this.gcExtItemDescs = new String[gcExtItemCount];
    this.gcExtItemTypes = new char[gcExtItemCount];

    // Fill the information about extension attributes
    fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames,
                        gcExtItemTypes, gcExtItemDescs);

    // lazily build the CompositeType for the GcInfo
    // including the GC-specific extension attributes
    this.gcInfoCompositeType = null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:GcInfoBuilder.java

示例8: getNext

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
/**
 * Returns the index that immediately follows the given
 * <var>index</var>. The returned index is strictly greater
 * than the given <var>index</var>, and is contained in the table.
 * <br>If the given <var>index</var> is null, returns the first
 * index in the table.
 * <br>If there are no index after the given <var>index</var>,
 * returns null.
 **/
public SnmpOid getNext(SnmpTableHandler handler, SnmpOid index) {

    // try to call the optimized method
    if (handler instanceof SnmpCachedData)
        return getNext((SnmpCachedData)handler, index);

    // too bad - revert to non-optimized generic algorithm
    SnmpOid next = index;
    do {
        next = handler.getNext(next);
        final Object value = handler.getData(next);
        if (value instanceof GarbageCollectorMXBean)
            // That's the next! return it
            return next;
        // skip to next index...
    } while (next != null);
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:JvmMemGCTableMetaImpl.java

示例9: getGcUsage

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThreadholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:JvmMetrics.java

示例10: readGCUsage

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
public static Map<String, Long> readGCUsage(List<GarbageCollectorMXBean> gcmbList) {

        Map<String, Long> m = new LinkedHashMap<String, Long>();

        for (GarbageCollectorMXBean gcmb : gcmbList) {

            String name = gcmb.getName();
            String gcName = null;
            if (minorGC.contains(name)) {
                gcName = "mgc";

            }
            else if (fullGC.contains(name)) {
                gcName = "fgc";
            }

            if (gcName == null) {
                continue;
            }

            m.put(gcName + "_count", gcmb.getCollectionCount());
            m.put(gcName + "_time", gcmb.getCollectionTime());
        }

        return m;
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:27,代碼來源:JVMToolHelper.java

示例11: readGCUsage

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
private void readGCUsage(MonitorElementInstance instance) {

        List<GarbageCollectorMXBean> gcmbList = ManagementFactory.getGarbageCollectorMXBeans();

        for (GarbageCollectorMXBean gcmb : gcmbList) {

            String name = gcmb.getName();
            String gcName = null;
            if (minorGC.contains(name)) {
                gcName = "mgc";

            }
            else if (fullGC.contains(name)) {
                gcName = "fgc";
            }

            if (gcName == null) {
                continue;
            }

            instance.setValue(gcName + "_count", gcmb.getCollectionCount());
            instance.setValue(gcName + "_time", gcmb.getCollectionTime());
        }
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:25,代碼來源:JVMStateCapHandler.java

示例12: main

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
public static void main(String [] args) throws Exception {
  if (args.length != 1) {
    throw new IllegalArgumentException("Usage: <MetaspaceSize>");
  }

  WhiteBox wb = WhiteBox.getWhiteBox();

  // Allocate past the MetaspaceSize limit.
  long metaspaceSize = Long.parseLong(args[0]);
  long allocationBeyondMetaspaceSize  = metaspaceSize * 2;
  long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);

  // Wait for at least one GC to occur. The caller will parse the log files produced.
  GarbageCollectorMXBean cmsGCBean = getCMSGCBean();
  while (cmsGCBean.getCollectionCount() == 0) {
    Thread.sleep(100);
  }

  wb.freeMetaspace(null, metaspace, metaspace);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TestCMSClassUnloadingEnabledHWM.java

示例13: allocateMemory

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
/**
 * Allocate (<b>ratio</b> * <b>maxSize</b> / 100) bytes of objects
 * and force at least "MaxTenuringThreshold" minor GCs.
 *
 * @param ratio ratio used to calculate how many objects should be allocated
 * @param maxSize estimated max survivor space size
 */
public static void allocateMemory(double ratio, long maxSize) throws Exception {
    GarbageCollectorMXBean youngGCBean = GCTypes.YoungGCType.getYoungGCBean();
    long garbageSize = (long) (maxSize * (ratio / 100.0));
    int arrayLength = (int) (garbageSize / CHUNK_SIZE);
    AllocationHelper allocator = new AllocationHelper(1, arrayLength, ARRAY_LENGTH, null);

    System.out.println(START_TEST);
    System.gc();
    final long initialGcId = youngGCBean.getCollectionCount();
    // allocate memory
    allocator.allocateMemoryAndVerify();

    // force minor GC
    while (youngGCBean.getCollectionCount() <= initialGcId + MAX_TENURING_THRESHOLD * 2) {
        byte b[] = new byte[ARRAY_LENGTH];
    }

    allocator.release();
    System.out.println(END_TEST);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:TestTargetSurvivorRatioFlag.java

示例14: isTenuredParallelGC

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
/**
 * Check if the tenured generation are currently using a parallel GC.
 */
protected static boolean isTenuredParallelGC() {
    // Currently the only parallel GC for the tenured generation is PS MarkSweep.
    List<String> parallelGCs = Arrays.asList(new String[] { "PS MarkSweep"});
    try {
        List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean bean : beans) {
            if (parallelGCs.contains(bean.getName())) {
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:JstatGcCapacityResults.java

示例15: getGCStatst

import java.lang.management.GarbageCollectorMXBean; //導入依賴的package包/類
/**
 * Returns a map of garbage collectors and their stats.
 * The first object in the array is the total count since JVM start and the
 * second is the total time (ms) since JVM start.
 * If a garbage collectors does not support the collector MXBean, then it
 * will not be represented in the map.
 * @return A non-null map of garbage collectors and their metrics. The map
 * may be empty.
 */
public static Map<String, Long[]> getGCStatst() {
  final List<GarbageCollectorMXBean> gcBeans =
      ManagementFactory.getGarbageCollectorMXBeans();
  final Map<String, Long[]> map = new HashMap<String, Long[]>(gcBeans.size());
  for (final GarbageCollectorMXBean bean : gcBeans) {
    if (!bean.isValid() || bean.getCollectionCount() < 0 ||
        bean.getCollectionTime() < 0) {
      continue;
    }

    final Long[] measurements = new Long[]{
        bean.getCollectionCount(),
        bean.getCollectionTime()
    };
    map.put(bean.getName().replace(" ", "_"), measurements);
  }
  return map;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:28,代碼來源:Utils.java


注:本文中的java.lang.management.GarbageCollectorMXBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。