java.lang.OutOfMemoryError: Java heap space
When you get the above error, please follow the below steps.
1) Checked the file where the Javaheapmemory needs to be increased. Developers can help you on this.
2) After identifying the file, increase it accordingly. For example:- If the current value is 2048m then increase it to 4096m. Issue will be resolved.
3) If you are having multiple servers then you need to run below bash script. In my case 20 instances are attached to Loadbalancer and need to change at a time. I used the below 2 scripts where the first script gives all the public Ips behind the load balancer. Second script will login to the servers and replace the heap memory values.
4) Before running the script install was-cli, you need to create IAM user and download the credentials of that IAM and run the below command.
aws configure
5) Give the access-key id and secret access key. After that you can run the script.
6) Create one bash file and copy the below script in to that. After that give permissions with the below command.
chmod +x file.sh
for ID in $(aws elb describe-load-balancers --load-balancer-name "YOURELB" \ --query LoadBalancerDescriptions[*].Instances[*].InstanceId \ --output=text); do aws ec2 describe-instances --instance-ids $ID \ --query Reservations[*].Instances[*].PublicIpAddress \ --output text done
7) Now run the script with the below command.
./file.sh > pubips.txt
8) Now the second script comes in to the picture where we can replace the heap memory values.
9) Please find the script below.
#!/bin/bash for z in $(cat pubips.txt); do echo $z ssh-keyscan $z >> /home/.ssh/known_hosts ssh -I YOURPEM.KEY YOUROSUSER@$z 'sed -i -e 's/-Xmx4096m/-Xmx8192m/g' /YOURHEAP/MEMORY/PATH/FILE' done
10) Restart you service and then the new value will be updated. You can check it by running the “Systemctl status service name”.
Note:- You can combine both the scripts and modify according to your requirement.