VM 启动后更改 java -Xmx
我有一个长时间运行的Java作业运行在我的计算机,当它接近尾声时,它的速度会大大减慢,因为它遇到了严重的内存压力,并且垃圾收集器必须频繁运行。换句话说,我低估了这项工作所需的最大堆大小 -Xmx
。
由于我不想重新启动作业,有什么方法可以让 JVM 在 JVM 启动后更改其最大堆大小,例如使用 jinfo -flag
或类似的东西?这可能吗?
我一直在尝试使用 jinfo -flag +Xmx1024m
或 jinfo -flag Xmx=1024m
的变体,它们都给了我以下异常。这是 Debian bug #532538 的症状吗(我是使用受影响的 JVM 版本),或者这是预期的行为(并且以后不可能更改 -Xmx
),或者我是否错误地向 jinfo
提供了标志?
Exception in thread "main" java.io.IOException: Command failed in target VM
at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:218)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:213)
at sun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java:190)
at sun.tools.jinfo.JInfo.flag(JInfo.java:129)
at sun.tools.jinfo.JInfo.main(JInfo.java:76)
Possible Duplicates:
Setting JVM heap size at runtime
programatically setting max java heap size
I have a long-running Java job running on my computer, and it's slowing down immensely when it gets near the end becuase it encounters serious memory pressure and the garbage collector has to run frequently. In other words, I underestimated the maximum heap size -Xmx
that I need for this job.
Since I don't want to restart the job, is there any way to make the JVM change it's maximum heap size after the JVM has already started, for example using jinfo -flag
or something like that? Is this possible?
I've been trying with variations on jinfo -flag +Xmx1024m
or jinfo -flag Xmx=1024m
, and they all give me the following exception. Is this a symptom of Debian bug #532538 (I am using the affected version of the JVM), or is this the expected behavior (and it's just impossible to change -Xmx
later), or am I providing the flag to jinfo
incorrectly?
Exception in thread "main" java.io.IOException: Command failed in target VM
at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:218)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:213)
at sun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java:190)
at sun.tools.jinfo.JInfo.flag(JInfo.java:129)
at sun.tools.jinfo.JInfo.main(JInfo.java:76)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不可能的。或者至少,不适用于任何平台上的任何现有 Sun JVM。
有关更多详细信息,请参阅上述评论中相关问题的答案。
不。
No. It is not possible. Or at least, not with any existing Sun JVM on any platform.
For more details, see the answers to the related questions per the comments above.
No.