How to increase JAVA Heap Size?

57,072

You could use java -Xmx4096m in order to set your heap to 4 GB.

you could then add export _JAVA_OPTIONS=-Xmx4096m to your shell by their (.bashrc, .zshrc) file.

Share:
57,072

Related videos on Youtube

Program man
Author by

Program man

It's my passion and job... So I have to work on all flavors of Linux. I am launching my own company very soon in the IT sector. Thank you all for giving support and to start such a good platform for all Linux users. Ubuntu rocks... :) Please feel free to contact me in case of any query on [email protected]

Updated on September 18, 2022

Comments

  • Program man
    Program man over 1 year

    I need to increase the default java heap size to get OpenNMS Linkd service running smoothly, and fortunately I have 4/5 of my total installed memory free at any given time even when their is maximum load on the server. still java is not performing to it's bast. hence I need to increase the default java heap size.

    Can anyone tell me how to do it?

    I'm using Ubuntu 12.04 lts & total memory installed is 16 GB out of which generally 2GB to 4GB is used.

    I have already checked below questions and they did not help me resolve my issue.

    1. How to increase memory allocated to java? java.lang.OutOfMemoryError: Java heap space

    2. Comparing Virtual Memory Size with Resident Size

    3. How to increase memory allocated to java? java.lang.OutOfMemoryError: Java heap space

    Please feel free to edit or comment for any additional details required.

  • josh.thomson
    josh.thomson about 9 years
    How do you check the current configuration of the heap size?
  • Taylor Ramirez
    Taylor Ramirez about 9 years
    if you run java -XshowSettings:vm, near the top it should say something like this "Max. Heap Size (Estimated): 2.60G"
  • josh.thomson
    josh.thomson about 9 years
    Would increasing the amount of RAM on the server remove the heap error? Here's my scenario: askubuntu.com/questions/611685/…
  • Taylor Ramirez
    Taylor Ramirez about 9 years
    depends if the heap is getting too big for the main memory, like if the heap hit 2GB and the RAM is only two GB you'd most likely get an error before that because there are other things in memory. now if the error is the program needs a bigger heap and Java has say 0.5GB as the max heap size and you need 1GB for the program, then it is more of a setting error than a hardware issue.
  • josh.thomson
    josh.thomson about 9 years
    Ah! here's my result: Max. Heap Size (Estimated): 494.94M ... So I guess it would be a good idea to increase the Heap Size to around 2GB. After some research I have found out there is a 3GB RAM limit on 32-bit Ubuntu 14.04 LTS systems (with a certain PAE config)... So I increased the RAM to 3GB (networking is working unaffected). I will try increasing the heap and see if that works! -Thanks for your assistance.
  • josh.thomson
    josh.thomson about 9 years
    I used 'java -Xmx2048m' to set the heap size to 2GB. However, the estimated heap size is still showing '494.94M'. Even after a reboot. ...I have started the script again... so hopefully it will complete this time. I will update with progress.
  • Taylor Ramirez
    Taylor Ramirez about 9 years
    you might have to set that in the defaults for Java otherwise you'll have to give it that argument each time.
  • josh.thomson
    josh.thomson about 9 years
    Thanks, I found the command needed :) Link to Thread
  • Taylor Ramirez
    Taylor Ramirez about 9 years
    That's good glad to help, also if my answer helped you there is an upvote button there ;)