How to fix Terminating due to java.lang.OutOfMemoryError: Java heap space error

Dhal, Sushreesmita 0 Reputation points
2024-01-30T13:31:45.9966667+00:00

My application is restarting multiple times with Terminating due to java.lang.OutOfMemoryError: Java heap space error. my configuration is like below , Please help on this

- name: JVM_OPTS
            value: -Xms5G -Xmx5G -XX:MaxMetaspaceSize=1024m -XX:ParallelGCThreads=16 -XX:+ExitOnOutOfMemoryError -javaagent:agent/applicationinsights-agent-3.4.12.jar   
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
697 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,040 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2024-01-30T13:31:46+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To fix the java.lang.OutOfMemoryError: Java heap space error, you can increase the maximum heap size allocated to the JVM. In your current configuration, you have set the initial heap size and maximum heap size to 5GB using the -Xms and -Xmx JVM options. However, this may not be sufficient for your application's memory requirements.

    You can try increasing the maximum heap size to a higher value, such as 8GB or 10GB, and see if it resolves the issue. You can do this by modifying the -Xmx option in your configuration.

    - name: JVM_OPTS
      value: -Xms5G -Xmx10G -XX:MaxMetaspaceSize=1024m -XX:ParallelGCThreads=16 -XX:+ExitOnOutOfMemoryError -javaagent:agent/applicationinsights-agent-3.4.12.jar
    

    Keep in mind that setting the maximum heap size too high can also cause issues such as container OOM, so you need to find a balance between the memory requirements of your application and the available resources.


    References:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.