• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GarbageCollectorMXBean类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: updateStampsAndStoreDifference

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public void updateStampsAndStoreDifference( /*out*/ final SingleIterationResult iterationResult ) {
	long totalGcCollectionCount = 0;
	long totalGcCollectionTime = 0;
	for( final GarbageCollectorMXBean gcBean : gcMXBeans ) {
		totalGcCollectionCount += gcBean.getCollectionCount();
		totalGcCollectionTime += gcBean.getCollectionTime();
	}

	final long bytesAllocatedByThread = threadMXBean.getThreadAllocatedBytes( benchmarkThreadId );

	iterationResult.fill(
			totalGcCollectionTime - gcCollectionTime,
			totalGcCollectionCount - gcCollectionCount,
			bytesAllocatedByThread - memoryAllocatedByThreadBytes
	);


	this.gcCollectionCount = totalGcCollectionCount;
	this.gcCollectionTime = totalGcCollectionTime;
	this.memoryAllocatedByThreadBytes = bytesAllocatedByThread;
}
 
开发者ID:cheremin,项目名称:scalarization,代码行数:22,代码来源:AllocationBenchmarkBuilder.java


示例2: registerGcMetrics

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
private static void registerGcMetrics(Map<String, Metric> metrics, long jvmStartTime, GarbageCollectorMXBean gcMxBean) {
    String gcName = gcMxBean.getName(), gcMetricNamePrefix = buildMetricName(GC_METRIC_NAME_PART, normalizeMetricDisplayName(gcName)),
        gcCollMetricNamePrefix = buildMetricName(gcMetricNamePrefix, COLLECTION_METRIC_NAME_PART);

    registerGauge(metrics, buildMetricName(gcMetricNamePrefix, NAME_METRIC_NAME_PART), gcName);
    registerGauge(metrics, buildMetricName(gcCollMetricNamePrefix, COUNT_METRIC_NAME_PART), gcMxBean.getCollectionCount());
    registerGauge(metrics, buildMetricName(gcCollMetricNamePrefix, TIME_METRIC_NAME_PART), gcMxBean.getCollectionTime());

    GcInfo gcInfo = gcMxBean.getLastGcInfo();

    if (gcInfo == null) {
        return;
    }

    String gcCollLastMetricNamePrefix = buildMetricName(gcCollMetricNamePrefix, LAST_METRIC_NAME_PART);

    registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, ID_METRIC_NAME_PART), gcInfo.getId());
    registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, TIME_START_METRIC_NAME_PREFIX), new Date((jvmStartTime + gcInfo.getStartTime())));
    registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, TIME_END_METRIC_NAME_PREFIX), new Date((jvmStartTime + gcInfo.getEndTime())));
    registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, DURATION_METRIC_NAME_PART), gcInfo.getDuration());

    registerGcMemoryUsageMetrics(metrics, buildMetricName(gcCollLastMetricNamePrefix, BEFORE_MEMORY_METRIC_NAME_PREFIX), gcInfo.getMemoryUsageBeforeGc());
    registerGcMemoryUsageMetrics(metrics, buildMetricName(gcCollLastMetricNamePrefix, AFTER_MEMORY_METRIC_NAME_PREFIX), gcInfo.getMemoryUsageAfterGc());
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:25,代码来源:GarbageCollectionMetricSet.java


示例3: processNotification

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public static void processNotification(MBeanServerConnection connection, Notification notification) {
    echo("\n<notification>");
    echo("\t<currentDatetime>" + DATE_FORMAT.format(Calendar.getInstance().getTime()) + "</currentDatetime>");
    echo("\t<notificationTime timestamp='" + notification.getTimeStamp() + "'>" + DATE_FORMAT.format(new Date(notification.getTimeStamp())) + "</notificationTime>");
    echo("\t<className>" + notification.getClass().getName() + "</className>");
    echo("\t<source>" + notification.getSource() + "</source>");
    echo("\t<type>" + notification.getType() + "</type>");
    echo("\t<message>" + notification.getMessage() + "</message>");
    if (notification instanceof AttributeChangeNotification) {
        echo("\t<attributeChanges>");
        AttributeChangeNotification acn = (AttributeChangeNotification) notification;
        echo("\t\t<attributeName>" + acn.getAttributeName() + "</attributeName>");
        echo("\t\t<attributeType>" + acn.getAttributeType() + "</attributeType>");
        echo("\t\t<newValue>" + acn.getNewValue() + "</newValue>");
        echo("\t\t<oldValue>" + acn.getOldValue() + "</oldValue>");
        echo("\t</attributeChanges>");
    }

    if (notification.getSource() instanceof ObjectName) {
        GarbageCollectorMXBean gcBean = JMX.newMXBeanProxy(connection, (ObjectName) notification.getSource(), GarbageCollectorMXBean.class);
        echo("\t<gcInfo>");
        echo("\t\t<collectionTime>" + gcBean.getCollectionTime() + "</collectionTime>");
        echo("\t\t<collectionCount>" + gcBean.getCollectionCount() + "</collectionCount>");
        GcInfo gcInfo = gcBean.getLastGcInfo();
        echo("\t\t<startTime>" + gcInfo.getStartTime() + "</startTime>");
        echo("\t\t<endTime>"   + gcInfo.getEndTime()   + "</endTime>");
        echo("\t\t<duration>"  + gcInfo.getDuration()  + "</duration>");
        outputMemoryUsages(gcInfo.getMemoryUsageBeforeGc(), "memoryUsageBeforeGC");
        outputMemoryUsages(gcInfo.getMemoryUsageAfterGc(), "memoryUsageAfterGC");
        echo("\t</gcInfo>");
    }

    echo("\n</notification>");
}
 
开发者ID:breakEval13,项目名称:rocketmq-flink-plugin,代码行数:35,代码来源:JMXGarbageCollectorNotificationClient.java


示例4: main

import com.sun.management.GarbageCollectorMXBean; //导入依赖的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


示例5: AllocationMonitor

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public AllocationMonitor( final Thread benchmarkThread ) {
	//noinspection SuspiciousToArrayCall
	gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans().toArray( new GarbageCollectorMXBean[0] );
	threadMXBean = ( ThreadMXBean ) ManagementFactory.getThreadMXBean();

	this.benchmarkThreadId = benchmarkThread.getId();
}
 
开发者ID:cheremin,项目名称:scalarization,代码行数:8,代码来源:AllocationBenchmarkBuilder.java


示例6: storeCurrentStamps

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public void storeCurrentStamps() {
	long collectionCounts = 0;
	long collectionTimes = 0;
	for( final GarbageCollectorMXBean gcBean : gcMXBeans ) {
		collectionCounts += gcBean.getCollectionCount();
		collectionTimes += gcBean.getCollectionTime();
	}
	this.gcCollectionCount = collectionCounts;
	this.gcCollectionTime = collectionTimes;

	this.memoryAllocatedByThreadBytes = threadMXBean.getThreadAllocatedBytes( benchmarkThreadId );
}
 
开发者ID:cheremin,项目名称:scalarization,代码行数:13,代码来源:AllocationBenchmarkBuilder.java


示例7: TestWriteSpeed2

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public TestWriteSpeed2(int count, int repeat, int phases) {
	this.count = count;
	this.repeat = repeat;
	this.phases = phases;
	osManagement = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
	for (Object bean : ManagementFactory.getGarbageCollectorMXBeans())
		gcManagement.add((GarbageCollectorMXBean)bean);
}
 
开发者ID:Devexperts,项目名称:QD,代码行数:9,代码来源:TestWriteSpeed2.java


示例8: getMetrics

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
@Override
public Map<String, Metric> getMetrics() {
    Map<String, Metric> metrics = super.getMetrics();
    long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();

    ManagementFactory.getGarbageCollectorMXBeans().forEach(gcMxBean -> registerGcMetrics(metrics, jvmStartTime, ((GarbageCollectorMXBean) gcMxBean)));

    return metrics;
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:10,代码来源:GarbageCollectionMetricSet.java


示例9: getGarbageCollectorMXBean

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
@Override
public GarbageCollectorMXBean getGarbageCollectorMXBean() {
    return new SemiSpaceGarbageCollectorMXBean();
}
 
开发者ID:beehive-lab,项目名称:Maxine-VM,代码行数:5,代码来源:SemiSpaceHeapScheme.java


示例10: getGarbageCollectorMXBean

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
@Override
public GarbageCollectorMXBean getGarbageCollectorMXBean() {
    return new GenSSGarbageCollectorMXBean();
}
 
开发者ID:beehive-lab,项目名称:Maxine-VM,代码行数:5,代码来源:GenSSHeapScheme.java


示例11: setNotificationEnabled

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
native void setNotificationEnabled(GarbageCollectorMXBean gc,
boolean enabled);
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:3,代码来源:GarbageCollectorImpl.java


示例12: getStat

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public MemoryPoolStat getStat() throws java.io.IOException {
    long usageThreshold = (pool.isUsageThresholdSupported()
                              ? pool.getUsageThreshold()
                              : -1);
    long collectThreshold = (pool.isCollectionUsageThresholdSupported()
                              ? pool.getCollectionUsageThreshold()
                              : -1);
    long lastGcStartTime = 0;
    long lastGcEndTime = 0;
    MemoryUsage beforeGcUsage = null;
    MemoryUsage afterGcUsage = null;
    long gcId = 0;
    if (lastGcInfo != null) {
        gcId = lastGcInfo.getId();
        lastGcStartTime = lastGcInfo.getStartTime();
        lastGcEndTime = lastGcInfo.getEndTime();
        beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
        afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
    }

    Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
    for (Map.Entry<ObjectName,Long> e : set) {
        GarbageCollectorMXBean gc =
            client.getMXBean(e.getKey(),
                             com.sun.management.GarbageCollectorMXBean.class);
        Long gcCount = e.getValue();
        Long newCount = gc.getCollectionCount();
        if (newCount > gcCount) {
            gcMBeans.put(e.getKey(), new Long(newCount));
            lastGcInfo = gc.getLastGcInfo();
            if (lastGcInfo.getEndTime() > lastGcEndTime) {
                gcId = lastGcInfo.getId();
                lastGcStartTime = lastGcInfo.getStartTime();
                lastGcEndTime = lastGcInfo.getEndTime();
                beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
                afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
                assert(beforeGcUsage != null);
                assert(afterGcUsage != null);
            }
        }
    }

    MemoryUsage usage = pool.getUsage();
    return new MemoryPoolStat(poolName,
                              usageThreshold,
                              usage,
                              gcId,
                              lastGcStartTime,
                              lastGcEndTime,
                              collectThreshold,
                              beforeGcUsage,
                              afterGcUsage);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:54,代码来源:MemoryPoolProxy.java


示例13: setNotificationEnabled

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
private native void setNotificationEnabled(GarbageCollectorMXBean gc,
boolean enabled);
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:3,代码来源:GarbageCollectorExtImpl.java


示例14: createGarbageCollector

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
private static java.lang.management.GarbageCollectorMXBean
    createGarbageCollector(String name, String type) {

    return new GarbageCollectorExtImpl(name);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:GarbageCollectorExtImpl.java


示例15: getStat

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public MemoryPoolStat getStat() throws java.io.IOException {
    long usageThreshold = (pool.isUsageThresholdSupported()
                              ? pool.getUsageThreshold()
                              : -1);
    long collectThreshold = (pool.isCollectionUsageThresholdSupported()
                              ? pool.getCollectionUsageThreshold()
                              : -1);
    long lastGcStartTime = 0;
    long lastGcEndTime = 0;
    MemoryUsage beforeGcUsage = null;
    MemoryUsage afterGcUsage = null;
    long gcId = 0;
    if (lastGcInfo != null) {
        gcId = lastGcInfo.getId();
        lastGcStartTime = lastGcInfo.getStartTime();
        lastGcEndTime = lastGcInfo.getEndTime();
        beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
        afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
    }

    Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
    for (Map.Entry<ObjectName,Long> e : set) {
        GarbageCollectorMXBean gc =
            client.getMXBean(e.getKey(),
                             com.sun.management.GarbageCollectorMXBean.class);
        Long gcCount = e.getValue();
        Long newCount = gc.getCollectionCount();
        if (newCount > gcCount) {
            gcMBeans.put(e.getKey(), newCount);
            lastGcInfo = gc.getLastGcInfo();
            if (lastGcInfo.getEndTime() > lastGcEndTime) {
                gcId = lastGcInfo.getId();
                lastGcStartTime = lastGcInfo.getStartTime();
                lastGcEndTime = lastGcInfo.getEndTime();
                beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
                afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
                assert(beforeGcUsage != null);
                assert(afterGcUsage != null);
            }
        }
    }

    MemoryUsage usage = pool.getUsage();
    return new MemoryPoolStat(poolName,
                              usageThreshold,
                              usage,
                              gcId,
                              lastGcStartTime,
                              lastGcEndTime,
                              collectThreshold,
                              beforeGcUsage,
                              afterGcUsage);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:54,代码来源:MemoryPoolProxy.java


示例16: GCLogger

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public GCLogger() {
    ManagementFactory.getGarbageCollectorMXBeans().stream().forEach(bean -> {
        GarbageCollectorMXBean gcBean = (GarbageCollectorMXBean) bean;
        ((NotificationEmitter) gcBean).addNotificationListener(this, null, null);
    });
}
 
开发者ID:kslisenko,项目名称:java-performance,代码行数:7,代码来源:GCLogger.java


示例17: collectTimes

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
private void collectTimes(Times times, int multiplier) {
	times.processCpuTime += multiplier * osManagement.getProcessCpuTime();
	for (GarbageCollectorMXBean bean : gcManagement)
		times.collectionTime += multiplier * bean.getCollectionTime();
}
 
开发者ID:Devexperts,项目名称:QD,代码行数:6,代码来源:TestWriteSpeed2.java


示例18: getStat

import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public MemoryPoolStat getStat() throws java.io.IOException {
    long usageThreshold = (pool.isUsageThresholdSupported() 
                              ? pool.getUsageThreshold() 
                              : -1);
    long collectThreshold = (pool.isCollectionUsageThresholdSupported() 
                              ? pool.getCollectionUsageThreshold() 
                              : -1);
    long lastGcStartTime = 0;
    long lastGcEndTime = 0;
    MemoryUsage beforeGcUsage = null;
    MemoryUsage afterGcUsage = null;
    long gcId = 0;
    if (lastGcInfo != null) {
        gcId = lastGcInfo.getId();
        lastGcStartTime = lastGcInfo.getStartTime();
        lastGcEndTime = lastGcInfo.getEndTime();
        beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
        afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
    }

    Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
    for (Map.Entry<ObjectName,Long> e : set) {
        GarbageCollectorMXBean gc = 
            client.getMXBean(e.getKey(),
                             com.sun.management.GarbageCollectorMXBean.class);
        Long gcCount = e.getValue();
        Long newCount = gc.getCollectionCount();
        if (newCount > gcCount) {
            gcMBeans.put(e.getKey(), new Long(newCount));
            lastGcInfo = gc.getLastGcInfo();
            if (lastGcInfo.getEndTime() > lastGcEndTime) {
                gcId = lastGcInfo.getId();
                lastGcStartTime = lastGcInfo.getStartTime();
                lastGcEndTime = lastGcInfo.getEndTime();
                beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
                afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
                assert(beforeGcUsage != null);
                assert(afterGcUsage != null);
            }
        }
    }

    MemoryUsage usage = pool.getUsage(); 
    return new MemoryPoolStat(poolName, 
                              usageThreshold, 
                              usage, 
                              gcId, 
                              lastGcStartTime, 
                              lastGcEndTime, 
                              collectThreshold, 
                              beforeGcUsage, 
                              afterGcUsage);
}
 
开发者ID:toomanyopenfiles,项目名称:jmxmon,代码行数:54,代码来源:MemoryPoolProxy.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SunMinMaxPage类代码示例发布时间:2022-05-21
下一篇:
Java BukkitCommand类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap