Java memory size

Source: Internet
Author: User
Tags xms

Cause:
The full name of PermGen space is Permanent Generation space, which refers to the Permanent storage area of the memory. This memory is mainly used by JVM to store Class and Meta information, when a Class is loaded, it will be placed in the PermGen space. It is different from the Heap region where the Class Instance is stored. GC (Garbage Collection) permGen space is not cleaned up during the main program running period. Therefore, if your application has a CLASS, 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:
1. manually set MaxPermSize
Modify TOMCAT_HOME/bin/catalina. bat (catalina. sh in Linux) and add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
Set JAVA_OPTS = % JAVA_OPTS %-server-XX: PermSize = 128 M-XX: MaxPermSize = 512 m

Catalina. sh:
JAVA_OPTS = "$ JAVA_OPTS-server-XX: PermSize = 128 M-XX: MaxPermSize = 512 m"
In fact, this issue may not only occur after a long time, but also occur during the development process. We often like SSH combinations to develop programs. When such a problem occurs, Tomcat, Spring, and Hibernate are always blamed. Because they dynamically generate classes, the permanent heap in JVM overflows. There are different solutions. Some people say that upgrading tomcat to the latest version does not even require tomcat. Some people suspect that the issue of spring is very intense in the spring Forum, because the use of CBLIB in spring in AOP will dynamically generate many classes.

So someone checked the more basic JVM and found the key to the problem. In the past, SUN's JVM divided the memory into different zones, one of which is the permenter area used to store a lot of classes and class descriptions. Originally SUN thought that this region was fixed during JVM startup, but he did not expect that the current dynamics would be so widely used. In addition, this region has a special garbage collection mechanism. The problem now is that gc cannot be recycled after classes are dynamically loaded to this region!
 
Java. lang. OutOfMemoryError: Java heap space
1. When the java program runs for a certain period of time. Java. lang. OutOfMemoryError: Java heap space exception is often thrown.
2. java heap space refers to memory leakage due to insufficient JVM memory.
Cause:
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.
NOTE: If 98% of the time in JVM is used for GC and the available Heap size is less than 2%, 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. bat and add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
Set JAVA_OPTS = % JAVA_OPTS %-server-Xms800m-Xmx800m-XX: MaxNewSize = 256 m

Or modify catalina. sh.
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "$ JAVA_OPTS-server-Xms800m-Xmx800m-XX: MaxNewSize = 256 m"

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.