increase the java heap size permanently?
Asked Answered
J

5

52

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.

I just dont want to have to remember to type -XmX1g everytime I run my java app from the command line...

There has to be an admin way to do this right?

Joslin answered 19/5, 2009 at 3:38 Comment(1)
Note, the latest Java 6 releases from Sun have increased standard heap limits.Giovannagiovanni
A
66

Apparently, _JAVA_OPTIONS works on Linux, too:

$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g
Anyhow answered 2/10, 2009 at 10:0 Comment(2)
I'd suggest replacing the ">" with "$" as the linux terminal prompt ends with $. At first I got confused by your answer as it resembles similar structure to a sub cli within the terminal. (eg. mysql)... which evidently has a prompt of '>'. Thanks for your answer (which, in my opinion should be the approved answer)... fingers crossed that my long running script doesn't fail after 3 hours now, changed my java heap size from 500mb to 2gb! Also, I was unsure if the 3rd line 'Picked...' was a part of the 2nd line.. so I tried both. (if that's just an output... would suggest prefix of 'Output: '. :)Lama
Thanks @josh.thomson, I've updated the answer with your suggestionAnyhow
G
26

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

Galvan answered 1/6, 2017 at 13:0 Comment(1)
It worked for me but after some time it is going down to same heap size as it was before on my ec2 tomcatMeill
M
24

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.

Miltiades answered 19/5, 2009 at 3:50 Comment(1)
The windows solution can be reached here.Skirret
O
4

what platform are you running?..
if its unix, maybe adding

alias java='java -Xmx1g'  

to .bashrc (or similar) work

edit: Changing XmX to Xmx

Outrelief answered 19/5, 2009 at 3:48 Comment(0)
S
2

if the platform is Linux, then adding an entry in bash_profile will help.

vim ~/.bash_profile

then add

export _JAVA_OPTIONS="-Xmx4g" 
Squamosal answered 1/2, 2022 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.