{"id":6557,"date":"2021-09-25T16:10:14","date_gmt":"2021-09-25T10:40:14","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=6557"},"modified":"2021-09-25T16:10:16","modified_gmt":"2021-09-25T10:40:16","slug":"java-lang-outofmemoryerror-java-heap-space","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/java-lang-outofmemoryerror-java-heap-space\/","title":{"rendered":"java.lang.OutOfMemoryError: Java heap space"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When you get the above error, please follow the below steps.<br><br>1) Checked the file where the Javaheapmemory needs to be increased. Developers can help you on this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">aws configure<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5) Give the access-key id and secret access key. After that you can run the script.<br><br>6) Create one bash file and copy the below script in to that. After that give permissions with the below command.<br><span class=\"has-inline-color has-vivid-cyan-blue-color\">chmod +x file.sh<\/span><br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for ID in $(aws elb describe-load-balancers --load-balancer-name \"YOURELB\" \\\n    --query LoadBalancerDescriptions[*].Instances[*].InstanceId \\\n    --output=text);\ndo\n    aws ec2 describe-instances --instance-ids $ID \\\n        --query Reservations[*].Instances[*].PublicIpAddress \\\n        --output text\ndone<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">7) Now run the script with the below command.<br>.\/file.sh &gt; pubips.txt<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">8) Now the second script comes in to the picture where we can replace the heap memory values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">9) Please find the script below.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\nfor z in $(cat pubips.txt); do\necho $z\nssh-keyscan $z &gt;&gt; \/home\/.ssh\/known_hosts\nssh -I YOURPEM.KEY YOUROSUSER@$z 'sed -i -e 's\/-Xmx4096m\/-Xmx8192m\/g' \/YOURHEAP\/MEMORY\/PATH\/FILE'\ndone<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">10) Restart you service and then the new value will be updated. You can check it by running the &#8220;Systemctl status service name&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:-<\/strong> You can combine both the scripts and modify according to your requirement. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you get the above error, please follow the below steps. 1) Checked the file where the Javaheapmemory needs to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[920,921,919],"class_list":["post-6557","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","tag-java-heap-out-of-memory","tag-java-heap-space","tag-out-of-memory","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1HL","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=6557"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6557\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}