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?
必须有一个管理方式来做到这一点吗?
4 个解决方案
#1
50
Apparently, _JAVA_OPTIONS
works on Linux, too:
显然,_JAVA_OPTIONS也适用于Linux:
$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g
#2
19
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中获取虚拟机选项。
#3
9
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
#4
3
what platform are you running?..
if its unix, maybe adding
你在运行什么平台?如果它是unix,可能会添加
alias java='java -XmX1g'
to .bashrc (or similar) work
到.bashrc(或类似的)工作
#1
50
Apparently, _JAVA_OPTIONS
works on Linux, too:
显然,_JAVA_OPTIONS也适用于Linux:
$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g
#2
19
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中获取虚拟机选项。
#3
9
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
#4
3
what platform are you running?..
if its unix, maybe adding
你在运行什么平台?如果它是unix,可能会添加
alias java='java -XmX1g'
to .bashrc (or similar) work
到.bashrc(或类似的)工作