Java. lang. OutOfMemoryError: Production of PermGen space or Java heap space

Source: Internet
Author: User
Tags xms

Take the tomcat environment as an example. Other WEB servers, such as jboss and weblogic, share the same principle.
1. java. lang. OutOfMemoryError: PermGen space
PermGen space stands for Permanent Generation space, which is the Permanent storage area of the memory,
This memory is mainly used by JVM to store Class and Meta information. When the Class is loaded, it will be placed in PermGen space,
Unlike the Heap region of the storage Instance, GC (Garbage Collection) does not
PermGen space is cleaned up. Therefore, if your application contains many classes, the PermGen space error may occur,
This error is common when the web server pre-compile the JSP. If your web app uses a large number of third-party jar files
This error message is generated when the default jvm size (4 MB) is exceeded.
Solution: manually set the MaxPermSize

Modify TOMCAT_HOME/bin/catalina. sh
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "-server-XX: PermSize = 64 M-XX: MaxPermSize = 128 m
Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.

Ii. java. lang. OutOfMemoryError: Java heap space
Heap size settings
The JVM Heap setting refers to the setting of the memory space that JVM can allocate during the java program running. The JVM automatically sets the Heap size value at startup,
The initial space (-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-Xmn-Xms-Xmx provided by JVM.
. The Heap size is the sum of Young Generation and Tenured Generaion.
Tip: if 98% is used for GC and the available Heap size is less than 2% in JVM, this exception is thrown.
Tip: the Heap Size should not exceed 80% of the available physical memory. Generally, you must set the-Xms and-Xmx options to the same, and-Xmn to the-Xmx value of 1/4.
Solution: manually set Heap size
Modify TOMCAT_HOME/bin/catalina. sh
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: MaxNewSize = 256 m"

Iii. Example:

JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: PermSize = 64 M-XX: MaxNewSize = 256 m-XX: MaxPermSize = 128 m-Djava. awt. headless = true"

As we all know, when a JAVA program is started, the JVM will allocate an initial memory and the maximum memory to this application. The initial memory and maximum memory will affect the performance of the program to a certain extent. For example, when applications use the maximum memory, the JVM needs to first perform garbage collection to release some occupied memory.
Therefore, to adjust the initial memory and maximum memory at Tomcat startup, you must declare to JVM, generally, when running JAVA programs, you can use mid-Xms-Xmx to adjust the initial memory and maximum memory of the application:
For example, java-Xms64m-Xmx128m a. jar.
Tomcat startup programs are packaged and cannot be directly used to change the memory Settings Using java-X... tomcat. Changing this setting in Tomcat
There are two methods:
1. Add the TOMCAT_OPTS and CATALINA_OPTS attributes to the environment variable,
For example, SET CATALINA_OPTS =-Xms64m-Xmx512m;
Ms is the smallest, mx is the largest, 64 m, m respectively refers to the memory capacity.

2. Modify the Catalina. bat file
In line 1, "rem Execute Java with the applicable properties ",
% _ EXECJAVA % JAVA_OPTS % CATALINA_OPTS % DEBUG_OPTS %-Djava. endorsed. dirs = "% JAVA_ENDORSED_DIRS %"-classpath "% CLASSPATH %"-Dcatalina. base = "% CATALINA_BASE %"-Dcatalina. home = "% CATALINA_HOME %"-Djava. io. tmpdir = "% CATALINA_TMPDIR %" % MAINCLASS % CMD_LINE_ARGS % ACTION % replace % CATALINA_OPTS % with-Xms64m-Xmx512m

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.