• <tfoot id='0AjG9'></tfoot>

        <small id='0AjG9'></small><noframes id='0AjG9'>

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

        <legend id='0AjG9'><style id='0AjG9'><dir id='0AjG9'><q id='0AjG9'></q></dir></style></legend>
          <bdo id='0AjG9'></bdo><ul id='0AjG9'></ul>

        鼓励 JVM 进行 GC 而不是增加堆?

        Encourage the JVM to GC rather than grow the heap?(鼓励 JVM 进行 GC 而不是增加堆?)

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

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

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

                <legend id='Gzyj6'><style id='Gzyj6'><dir id='Gzyj6'><q id='Gzyj6'></q></dir></style></legend>
                <tfoot id='Gzyj6'></tfoot>
                    <tbody id='Gzyj6'></tbody>

                  本文介绍了鼓励 JVM 进行 GC 而不是增加堆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  (请注意,当我说JVM"时,我的意思是热点",我正在运行最新的 Java 1.6 更新.)

                  (Note that when I say "JVM", I really mean "Hotspot", and I'm running the latest Java 1.6 update.)

                  示例情况:

                  我的 JVM 运行时 -Xmx 设置为 1gb.目前,堆分配了 500mb,其中 450mb 被使用.该程序需要在堆上再加载 200 mb.目前,堆中有 300mb 的可收集"垃圾(我们假设它们都在最老的一代中.)

                  My JVM is running with -Xmx set to 1gb. Currently, the heap has 500mb allocated, of which 450mb is used. The program needs to load another 200 mb on the heap. Currently, there is 300mb worth of "collectable" garbage in the heap (we'll assume it's all in the oldest generation.)

                  在正常操作下,JVM 会将堆增加到 700 mb 左右,并在到达时进行垃圾收集.

                  Under normal operation, the JVM will grow the heap to 700 mb or so, and garbage collect when it gets around to it.

                  在这种情况下,我希望 JVM 先 gc,然后分配新的东西,这样我们最终的堆大小保持在 500mb,使用的堆大小保持在 350mb.

                  What I would like in that situation is for the JVM to gc first, then allocate the new stuff, so that we end up with the heap size staying at 500mb, and the used heap at 350mb.

                  是否有一个 JVM 参数组合可以做到这一点?

                  Is there a JVM parameter combo that does that?

                  推荐答案

                  你可以尝试指定 -XX:MinHeapFreeRatio-XX:MaxHeapFreeRatio 来控制堆的扩展和收缩:

                  You could try specifying -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio to control heap expansion and shrinking:

                  • -XX:MinHeapFreeRatio - 当一代中可用空间的百分比低于该值时,该代将扩展以满足该百分比.默认值为 40.
                  • -XX:MaxHeapFreeRatio - 当一代中可用空间的百分比超过该值时,该代将收缩以满足该值.默认值为 70.
                  • -XX:MinHeapFreeRatio - when the percentage of free space in a generation falls below this value the generation will be expanded to meet this percentage. Default is 40.
                  • -XX:MaxHeapFreeRatio - when the percentage of free space in a generation exceeded this value the generation will shrink to meet this value. Default is 70.

                  您可能还想通过指定 -XX:+UseConcMarkSweepGC 来试验并发 GC.根据您的应用程序,它可以以额外的 CPU 周期为代价来降低堆大小.

                  You might also want to experiment with concurrent GC by specifying -XX:+UseConcMarkSweepGC. Depending on your application it could keep the heap size lower at the cost of additional CPU cycles.

                  JVM 会在最佳情况下使用您指定的可用内存.您可以指定一个较小的量,例如 -Xmx768m 以保持它包含在内并且它可能运行良好,尽管您会增加在重负载情况下耗尽内存的风险.真正使用更少内存的唯一方法是编写使用更少内存的代码:)

                  The JVM is otherwise going to use the memory you specify as available when it's optimal do to so. You could specify a lower amount like -Xmx768m to keep it contained and it might run fine, although you would increase your risk of running out of memory in a heavy load scenario. Really the only way to use less memory overall is to write code that uses less memory :)

                  这篇关于鼓励 JVM 进行 GC 而不是增加堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                  ClassCastException because of classloaders?(ClassCastException 因为类加载器?)
                  How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                  Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                  Why a sawtooth shaped graph?(为什么是锯齿形图形?)
                  Singleton across JVM or Application instance or Tomcat instance(跨 JVM 或 Application 实例或 Tomcat 实例的单例)

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

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

                        <tbody id='aXRTn'></tbody>
                    1. <legend id='aXRTn'><style id='aXRTn'><dir id='aXRTn'><q id='aXRTn'></q></dir></style></legend>
                        <bdo id='aXRTn'></bdo><ul id='aXRTn'></ul>