"Go" Java Memory overflow (java.lang.OutOfMemoryError) problem and its solution

Source: Internet
Author: User

Java Memory Overflow (java.lang.OutOfMemoryError) problem and its solution

There are two cases of memory overflow, as follows:

Related configurations take the Tomcat environment as an example

One, Java.lang.OutOfMemoryError:PermGen space

The full name of PermGen space is permanent Generation space, which is the permanent storage area of memory, which is primarily stored by the JVM with class and meta information.

Class is placed in PermGen space when it is loader, unlike the heap area where the class instance (Instance) is stored, the GC (garbage Collection) does not clean up permgen space during the main program run time.

So if you have a lot of classes in your application, you are likely to have PermGen space errors, which are common when the Web server pre-compile the JSP.

If you have a large number of third-party jars under your web app that are larger than the JVM's default size (4M), this error message will be generated.

Workaround: Manually configure the MaxPermSize size

A) for compressed-package version of Tomcat

Modify Tomcat_home/bin/catalina.sh

Add the following line above the echo "Using catalina_base: $CATALINA _base":

Java_opts= "-server-xx:permsize=128m-xx:maxpermsize=512m

Or

Modify tomcat_home/bin/catalina.bat file

On the Echo Using catalina_base: "%catalina_base%", add the following line

Set java_opts=%java_opts%-server-xx:permsize=128m-xx:maxpermsize=512m

b) for the installed version of Tomcat, This diagram contains the settings for PermGen space and heap space.

    

On the last side of the Java Options option, add:
-xx:permsize=256m
-xx:maxpermsize=386m
-xms1024m
-xmx1024m

Note: there can be no space behind, or it will be an error

Recommendation: Move the same third-party jar files to the Tomcat/shared/lib directory, which can reduce the memory consumption of the jar document.

Second, Java.lang.OutOfMemoryError:Java heap space

The JVM heap setting is the set of memory space that the JVM can provision during the run of the Java program. The JVM automatically sets the value of the heap size when it is started.

its initial space (that is,-XMS) is 1/64 of the physical memory, and the maximum space (-XMX) is 1/4 of the physical memory. You can use options such as the-XMN-XMS-XMX provided by the JVM to

To set. The size of Heap size is the sum of young Generation and tenured generaion.

Tips: This exception information is thrown in the JVM if 98% of the time is used for GC and the available heap size is less than 2%.

Tips: The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4.

Workaround: Manually set the heap size

A) for compressed-package version of Tomcat

Modify Tomcat_home/bin/catalina.sh

Add the following line above the echo "Using catalina_base: $CATALINA _base":

Java_opts= "-server-xms800m-xmx800m-xx:maxnewsize=256m"

Or

Modify Tomcat_home/bin/catalina.bat

On the Echo Using catalina_base: "%catalina_base%", add the following line

Set java_opts=%java_opts%-server-xms800m-xmx800m-xx:maxnewsize=256m

b) for the installation version of Tomcat, such as.

How to set the above two items together can be combined into the above settings.

Transfer from http://my.oschina.net/colorleaf/blog/175581 network Source: Amoy Network Note: Reprint please indicate the source

"Go" Java Memory overflow (java.lang.OutOfMemoryError) problem and its solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.