如何以编程方式增加Java堆大小 [英] How to increase java heap size programmatically

查看:141
本文介绍了如何以编程方式增加Java堆大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于搜索文件的java桌面应用程序,它通常很快就会达到默认的堆限制。我无法访问将要安装的所有系统,因此我想在应用程序本身中增加JVM堆大小。任何人都可以帮助我如何在我的应用程序中以编程方式执行此操作

I have a java desktop application for searching files and it is usually reaching the default heap limit pretty soon. I wont have access to all the systems it will be installed in so I want to increase the JVM heap size in the application itself. Can anybody help me how can I do that programmatically in my application

推荐答案

将-Xmx设置为一个演出并不意味着JVM将在启动时分配大量内存。 JVM将仅分配-Xms(加上开销),直到需要更多堆空间。您是否需要保护您的用户免受虚拟内存抖动或操作系统内存分配失败的影响?如果没有,只需将Xmx设置为较大的值即可。请注意,Windows 32位JVM通常会忽略大于1.2Gig的Xmx设置,因此最好不要求大于gig的安全性。

Setting -Xmx to one gig doesn't mean that the JVM will allocate that much memory upon start-up. The JVM will allocate only -Xms (plus overhead) until more heap space is needed. Do you need to protect your users from thrashing virtual memory or a failed memory allocation from the OS? If not, just set Xmx to a large value. Note that Windows 32bit JVMs will often ignore Xmx settings greater than 1.2Gig, so it's best to not request more than a gig or so to be safe.

这篇关于如何以编程方式增加Java堆大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆