Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allocate space to JAVA using command line [duplicate]

Tags:

java

I have come across heap errors while loading a large dataset into Jena. `Is there some way by which I may allocate the JVM(Java) a large heap space.

I know I can achieve this by making changes into eclipse.ini. But is there some way by which I may increase the Java heap size using command line in linux (I using a 64GB RAM server: running 12.04 Ubuntu LTS server)?

The error which I am getting due to less heap space is: exception in thread main gc overhead limit exceeded.

Also how can I find the maximum amount of heap space which I can set for my systems

I tried export JAVA_OPTS= -Xms4096m -Xmx4096m but ended up getting the error: bash: export: -Xms4096m': not a valid identifier bash: export:-Xmx4096m': not a valid identifier

like image 728
Alice Everett Avatar asked May 23 '26 16:05

Alice Everett


2 Answers

Try (note quotes are not optional with two words)

export JAVA_OPTS="-Xms4096m -Xmx4096m"

Or, even

export MIN="4096m" # <-- Those quotes are (one word).
export MAX="4096m"
export JAVA_OPTS="-Xms$MIN -Xmx$MAX" # <-- single quotes would break variable expansion
like image 89
Elliott Frisch Avatar answered May 25 '26 05:05

Elliott Frisch


java -Xms4096m -Xmx4096m [YourAppHere]

This command will allocate 4GB (or 4096 MB) of heap memory at the start (the -Xms4096m option), and will have a maximum heap memory size of 4GB (the -Xmx4096m option).

Obviously you can change the number to whatever sizes you want to. There is overhead if the computer has to increase the size of memory (Every time it increases the memory size, it doubles the allocation) so if you have that much ram, you might as well just allocate it at the beginning of the app.

like image 40
oconnecp Avatar answered May 25 '26 06:05

oconnecp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!