问题描述
有没有办法从正在运行的 Java 程序中设置堆大小?
Is there a way to set heap size from a running Java program?
推荐答案
没有.
对于堆要求非常多变的应用,您可以使用 -Xmx 将最大堆大小设置得非常高,并调整 -XX:MaxHeapFreeRatio 和 -XX:MinHeapFreeRatio 以便应用程序在堆收缩时不会挂起大量内存(它使用默认设置执行此操作).
What you can do with an app that has very variable heap requirements is to set your max heap size very high with -Xmx and tune -XX:MaxHeapFreeRatio and -XX:MinHeapFreeRatio so that the app will not hang on to a lot of memory when the heap shrinks (it does that with default settings).
但请注意,当应用实际使用的内存变化剧烈且迅速时,这可能会导致性能问题 - 在这种情况下,您最好将其挂在所有内存上,而不是仅将其返回给操作系统一秒钟后再次申领.您可能还想摆弄 GC 选项 以确保 GC不会留下太多无人认领的对象,当堆有很大的增长空间时,它往往会这样做,这会破坏希望堆大小适应应用程序需求的目标.
But note that this may cause performance problems when the memory actually used by the app varies both strongly and quickly - in that case you're better off having it hang on to all the memory rather than give it back to the OS only to claim it again a second later. You might also want to fiddle with the GC options to ensure that the GC doesn't leave too much unclaimed objects lying around, which it tends to do when there's a lot of room for the heap to grow, and which would defeat the goal of wanting the heap size to adjust to the app's needs.
这篇关于在运行时设置 JVM 堆大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)