资讯专栏INFORMATION COLUMN

Java读取GC的耗时和次数

Leo_chen / 803人阅读

代码
    public static void main(String[] args) {
        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
            long count = gc.getCollectionCount();
            long time = gc.getCollectionTime();
            String name = gc.getName();
            System.out.println(String.format("%s: %s times %s ms", name, count, time));
        }
    }
结果

一个young generation collector和一个old generation collector

PS Scavenge: 0 times 0 ms
PS MarkSweep: 0 times 0 ms
Young generation collectors
Copy (enabled with -XX:+UseSerialGC)

the serial copy collector, uses one thread to copy surviving objects from Eden to Survivor spaces and between Survivor spaces until it decides they"ve been there long enough, at which point it copies them into the old generation.

PS Scavenge (enabled with -XX:+UseParallelGC)

the parallel scavenge collector, like the Copy collector, but uses multiple threads in parallel and has some knowledge of how the old generation is collected (essentially written to work with the serial and PS old gen collectors).

ParNew (enabled with -XX:+UseParNewGC)

the parallel copy collector, like the Copy collector, but uses multiple threads in parallel and has an internal "callback" that allows an old generation collector to operate on the objects it collects (really written to work with the concurrent collector).

G1 Young Generation (enabled with -XX:+UseG1GC)

the garbage first collector, uses the "Garbage First" algorithm which splits up the heap into lots of smaller spaces, but these are still separated into Eden and Survivor spaces in the young generation for G1.

Old generation collectors
MarkSweepCompact (enabled with -XX:+UseSerialGC)

the serial mark-sweep collector, the daddy of them all, uses a serial (one thread) full mark-sweep garbage collection algorithm, with optional compaction.

PS MarkSweep (enabled with -XX:+UseParallelOldGC)

the parallel scavenge mark-sweep collector, parallelised version (i.e. uses multiple threads) of the MarkSweepCompact.

ConcurrentMarkSweep (enabled with -XX:+UseConcMarkSweepGC)

the concurrent collector, a garbage collection algorithm that attempts to do most of the garbage collection work in the background without stopping application threads while it works (there are still phases where it has to stop application threads, but these phases are attempted to be kept to a minimum). Note if the concurrent collector fails to keep up with the garbage, it fails over to the serial MarkSweepCompact collector for (just) the next GC.

G1 Mixed Generation (enabled with -XX:+UseG1GC)

the garbage first collector, uses the "Garbage First" algorithm which splits up the heap into lots of smaller spaces.

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/76336.html

相关文章

  • [译]GC专家系列2:Java 垃圾回收监控

    摘要:原文链接这是专家系列文章的第二篇。运行在本地虚拟机上的应用的又称为,通常与相同。性能数据需要持续观察,因此在运行时需要定时输出的监控信息。新生代容量的统计信息。是提供的一个式的图表监控工具。 原文链接:http://www.cubrid.org/blog/dev-platform/how-to-monitor-java-garbage-collection/ 这是GC专家系列文章的第二...

    yiliang 评论0 收藏0
  • [译]GC专家系列3-GC调优

    摘要:原文链接本篇是专家系列的第三篇。但是,请记住调优是不得已时的选择。缩短耗时的单次执行与相比,耗时有较明显的增加。创建文件过程中,进程会中断,因此不要在正常运行时系统上做此操作。因此校验结果并根据具体的服务需要,决定是否要进行调优。 原文链接:http://www.cubrid.org/blog/dev-platform/how-to-tune-java-garbage-collecti...

    leap_frog 评论0 收藏0
  • 江义旺:滴滴出行安卓端 finalize time out 解决方案

    摘要:此前滴滴出行安卓端曾长期受此的影响,每天有一些用户会因此遇到,经过深度分析,最终找到有效解决方案。方法内尽量减少耗时以及线程同步时间。减少高优先级线程的创建和使用,降低高优先级线程的使用率。出品 | 滴滴技术作者 | 江义旺showImg(https://user-gold-cdn.xitu.io/2019/5/15/16ab95686cf247c1);前言:随着安卓 APP 规模越来越大,...

    Betta 评论0 收藏0
  • 《深入理解Java虚拟机》(四)虚拟机性能监控与故障处理工具

    摘要:虚拟机性能监控与故障处理工具详解概述本文参考的是周志明的深入理解虚拟机第四章,为了整理思路,简单记录一下,方便后期查阅。虚拟机堆转储快照分析工具功能用于分析生成的。 虚拟机性能监控与故障处理工具 详解 4.1 概述 本文参考的是周志明的 《深入理解Java虚拟机》 第四章 ,为了整理思路,简单记录一下,方便后期查阅。 JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的Vis...

    gself 评论0 收藏0
  • 逐梦offer -- JVM篇

    摘要:的字节码解释器和编译器使用写屏障维护卡表。解释器每次执行更新引用的字节码时,都会执行一段写屏障,编译器在生成更新引用的代码后,也会生成一段写屏障。 4. JVM 4.1 GC 1. 垃圾收集 基础 : 可达性分析算法 GC ROOTS 复制算法 标记清除 标记整理 分代收集 -- 1. 新生代 ; 2.3 老年代注: Oop Map -- 安全点 -- 安全区 以下部分内容 来自 ...

    greatwhole 评论0 收藏0

发表评论

0条评论

Leo_chen

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<