<bdo id='mKeV2'></bdo><ul id='mKeV2'></ul>

    <small id='mKeV2'></small><noframes id='mKeV2'>

  1. <tfoot id='mKeV2'></tfoot>

      <i id='mKeV2'><tr id='mKeV2'><dt id='mKeV2'><q id='mKeV2'><span id='mKeV2'><b id='mKeV2'><form id='mKeV2'><ins id='mKeV2'></ins><ul id='mKeV2'></ul><sub id='mKeV2'></sub></form><legend id='mKeV2'></legend><bdo id='mKeV2'><pre id='mKeV2'><center id='mKeV2'></center></pre></bdo></b><th id='mKeV2'></th></span></q></dt></tr></i><div id='mKeV2'><tfoot id='mKeV2'></tfoot><dl id='mKeV2'><fieldset id='mKeV2'></fieldset></dl></div>
    1. <legend id='mKeV2'><style id='mKeV2'><dir id='mKeV2'><q id='mKeV2'></q></dir></style></legend>

    2. 你能在 Java 中获得基本的 GC 统计信息吗?

      时间:2023-07-12

        <tfoot id='VoXIH'></tfoot>

        <small id='VoXIH'></small><noframes id='VoXIH'>

          <tbody id='VoXIH'></tbody>
      1. <legend id='VoXIH'><style id='VoXIH'><dir id='VoXIH'><q id='VoXIH'></q></dir></style></legend>

            <i id='VoXIH'><tr id='VoXIH'><dt id='VoXIH'><q id='VoXIH'><span id='VoXIH'><b id='VoXIH'><form id='VoXIH'><ins id='VoXIH'></ins><ul id='VoXIH'></ul><sub id='VoXIH'></sub></form><legend id='VoXIH'></legend><bdo id='VoXIH'><pre id='VoXIH'><center id='VoXIH'></center></pre></bdo></b><th id='VoXIH'></th></span></q></dt></tr></i><div id='VoXIH'><tfoot id='VoXIH'></tfoot><dl id='VoXIH'><fieldset id='VoXIH'></fieldset></dl></div>

              • <bdo id='VoXIH'></bdo><ul id='VoXIH'></ul>
                本文介绍了你能在 Java 中获得基本的 GC 统计信息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想让一些长时间运行的服务器应用程序定期输出 Java 中的一般 GC 性能数字,比如 Runtime.freeMemory() 等 GC 等值.比如完成的周期数、平均时间等.

                I would like to have some long-running server applications periodically output general GC performance numbers in Java, something like the GC equivalent of Runtime.freeMemory(), etc. Something like number of cycles done, average time, etc.

                我们的系统在客户机器上运行,怀疑配置错误的内存池会导致过多的 GC 频率和长度 - 我认为定期报告基本 GC 活动通常是好的.

                We have systems running on customer machines where there is a suspicion that misconfigured memory pools are causing excessive GC frequency and length - it occurs to me that it would be good in general to periodically report the basic GC activity.

                是否有任何独立于平台的方式来做到这一点?

                Is there any platform independent way to do this?

                我特别想在运行时将此数据输出到系统日志(控制台);这不是我想连接到 JVM 的东西,就像 JConsole 或 JVisualVM 一样.

                Edit2:MX bean 看起来像我想要的 - 有没有人有一个获得其中之一的工作代码示例?

                The MX bean looks like what I want - does anyone have a working code example which obtains one of these?

                推荐答案

                这是一个使用 GarbageCollectorMXBean 打印出 GC 统计信息.大概您会定期调用此方法,例如使用 ScheduledExecutorService 进行调度.

                Here's an example using GarbageCollectorMXBean to print out GC stats. Presumably you would call this method periodically, e.g. scheduling using a ScheduledExecutorService.

                public 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);
                }
                

                这篇关于你能在 Java 中获得基本的 GC 统计信息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Java 中对变量使用 final 会改善垃圾收集吗? 下一篇:在 Java 中是否收集了永久代空间垃圾?

                相关文章

                1. <i id='1O0zY'><tr id='1O0zY'><dt id='1O0zY'><q id='1O0zY'><span id='1O0zY'><b id='1O0zY'><form id='1O0zY'><ins id='1O0zY'></ins><ul id='1O0zY'></ul><sub id='1O0zY'></sub></form><legend id='1O0zY'></legend><bdo id='1O0zY'><pre id='1O0zY'><center id='1O0zY'></center></pre></bdo></b><th id='1O0zY'></th></span></q></dt></tr></i><div id='1O0zY'><tfoot id='1O0zY'></tfoot><dl id='1O0zY'><fieldset id='1O0zY'></fieldset></dl></div>

                    <small id='1O0zY'></small><noframes id='1O0zY'>

                    <tfoot id='1O0zY'></tfoot><legend id='1O0zY'><style id='1O0zY'><dir id='1O0zY'><q id='1O0zY'></q></dir></style></legend>
                    • <bdo id='1O0zY'></bdo><ul id='1O0zY'></ul>