Solve PermGen space Tomcat memory settings

Source: Internet
Author: User
Tags jboss xms

When a Java program is used to query a large amount of data from the database or the application server (such as tomcat, jboss, and weblogic) loads the jar package, a java. lang. OutOfMemoryError error occurs. This is mainly caused by insufficient memory on the application server. This exception often happens in the following situations (taking 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 is called Permanent Generation space, which refers to the Permanent storage area of the memory OutOfMemoryError: PermGen space. In terms of text, memory overflow occurs. The solution is to increase the memory. Why is the memory overflow? This is because the memory is mainly used by JVM to store Class and Meta information. When the Class is loaded, it is placed in the PermGen space area, unlike the Heap region where the Instance is stored, GC (Garbage Collection) does not clean up PermGen space during the main program running, so if your APP loads a lot of 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 and the size exceeds the default jvm size (4 MB), this error message is generated.
Solution: manually set the MaxPermSize
A. If tomcat is started in bat mode, set it as follows:
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
B. If tomcat is registered as a windows Service and started in services Mode, You need to modify the corresponding key value in the registry.
Open the registry and find the HKEY_LOCAL_MACHINE \ SOFTWARE \ Apache Software Foundation \ Procrun 2.0 \ htfty \ Parameters \ Java directory. The red mark (such as htfty) in the directory address needs to be modified according to different situations, register the tomcat service as the name of the windows service. JvmMs and JvmMx are displayed. JvmMs sets the minimum memory usage parameters and JvmMx sets the maximum memory usage parameters. Set the values of JvmMs and JvmMx, and restart the tomcat server.
Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.
2. java. lang. OutOfMemoryError: Java heap space
The JVM heap setting refers to the setting of the memory space that JVM can allocate during 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 to set the configuration. The Heap size is the sum of Young Generation and Tenured Generaion. This exception is thrown if 98% is used for GC and the available Heap size is less than 2% in JVM.
Solution: manually set Heap size
A. If tomcat is started in bat mode, set it as follows:
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"
B. If tomcat is registered as a windows Service and started in services Mode, You need to modify the corresponding key value in the registry.
Open the registry and find the HKEY_LOCAL_MACHINE \ SOFTWARE \ Apache Software Foundation \ Procrun 2.0 \ htfty \ Parameters \ Java directory. The red mark (such as htfty) in the directory address needs to be modified according to different situations, register the tomcat service as the name of the windows service. JvmMs and JvmMx are displayed. JvmMs sets the minimum memory usage parameters and JvmMx sets the maximum memory usage parameters. Set the values of JvmMs and JvmMx, and restart the tomcat server.

Related Article

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.