rufus
rufus

Reputation:

increase the java heap size permanently?

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?

Upvotes: 52

Views: 123956

Answers (5)

mauryaAjay
mauryaAjay

Reputation: 279

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

vim ~/.bash_profile

then add

export _JAVA_OPTIONS="-Xmx4g" 

Upvotes: 2

Aditya Mukherji
Aditya Mukherji

Reputation: 9256

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

alias java='java -Xmx1g'  

to .bashrc (or similar) work

edit: Changing XmX to Xmx

Upvotes: 4

juic3n
juic3n

Reputation: 419

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

Upvotes: 26

Kutzi
Kutzi

Reputation: 1321

Apparently, _JAVA_OPTIONS works on Linux, too:

$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g

Upvotes: 66

The Dissonant
The Dissonant

Reputation: 323

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.

Upvotes: 24

Related Questions