Setting JVM heap size at runtime(在运行时设置 JVM 堆大小)
问题描述
有没有办法从正在运行的 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 堆大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在运行时设置 JVM 堆大小
基础教程推荐
- 将 double 转换为 Int,向下舍入 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- JPA惰性列表上的流 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
