永久增加java堆大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/880855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
increase the java heap size permanently?
提问by
Is there a way that I can set the default heap size for the jvm on my own computer? I want to set it to 1g, because I'm always running custom programs that always hit the overage point in the default jvm size.
有没有办法可以在我自己的计算机上为 jvm 设置默认堆大小?我想将它设置为 1g,因为我总是在运行自定义程序,这些程序总是达到默认 jvm 大小的超额点。
I just dont want to have to remember to type -XmX1g everytime I run my java app from the command line...
我只是不想每次从命令行运行我的 Java 应用程序时都要记住输入 -XmX1g ......
There has to be an admin way to do this right?
必须有一种管理方式才能做到这一点吗?
回答by Aditya Mukherji
what platform are you running?..
if its unix, maybe adding
你在运行什么平台?...
如果是unix,也许添加
alias java='java -Xmx1g'
to .bashrc (or similar) work
.bashrc(或类似的)工作
edit: Changing XmX to Xmx
编辑:将 XmX 更改为 Xmx
回答by The Dissonant
For Windows users, you can add a system environment variable named _JAVA_OPTIONS, and set the heap size values there. The JVM should be able to grab the virtual machine options from _JAVA_OPTIONS.
对于 Windows 用户,您可以添加一个名为 _JAVA_OPTIONS 的系统环境变量,并在那里设置堆大小值。JVM 应该能够从 _JAVA_OPTIONS 获取虚拟机选项。
回答by Kutzi
Apparently, _JAVA_OPTIONS
works on Linux, too:
显然,也_JAVA_OPTIONS
适用于 Linux:
$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g
回答by Justin Chitla
This worked for me:
这对我有用:
export _JAVA_OPTIONS="-Xmx1g"
It's important that you have no spaces because for me it did not work. I would suggest just copying and pasting. Then I ran:
重要的是你没有空格,因为对我来说它不起作用。我建议只是复制和粘贴。然后我跑了:
java -XshowSettings:vm
and it will tell you:
它会告诉你:
Picked up _JAVA_OPTIONS: -Xmx1g
拿起_JAVA_OPTIONS:-Xmx1g