JVM Memory Overflow resolution (how JVM Memory overflow resolves) _java

Source: Internet
Author: User
Tags garbage collection tomcat xms

Java.lang.OutOfMemoryError:PermGen Space

Found that many people attribute the problem to: Spring,hibernate,tomcat, because they generate classes dynamically, causing permanent heap overflow in the JVM. Then there is a divergence of opinions about how to upgrade the Tomcat version to the latest or even simply without Tomcat. There are also questions about spring that are hotly discussed at the Spring Forum, because spring's use of cblib in AOP creates many classes dynamically.
But the question is why are the same problems with the open source of these trump cards, and is it a more fundamental reason? Tomcat in Q&a very vague answer to this, we know the problem, but this problem is caused by a more fundamental problem.
Then someone examined the more basic JVM and found the key to the problem. Originally, the Sun's JVM divided the memory into different areas, one of which was the Permenter area used to store a very much used class and class description. Sun was originally designed to assume that the area was fixed when the JVM was started, but he did not expect the current dynamics to be so widespread. And this area has a special garbage recovery mechanism, now the problem is to dynamically load the class to this area, the GC is simply no way to recycle!

1, first is: Java.lang.OutOfMemoryError:Java heap space

Explain:

Heap Size Setting

The JVM heap setting is the setting of the memory space that the JVM can allocate to the Java program while it is running. The JVM automatically sets the value of heap size when it starts, and its initial space (i.e.-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 set it up. Heap size is the sum of young Generation and tenured generaion.
Tip: This exception message is thrown in the JVM if 98% of the time is for GC and the available heap size is less than 2%.
Tip: Heap Size is not greater than 80% of the available physical memory, typically to set the-XMS and-XMX options to the same, and-xmn to the-XMX value of 1/4.

Workaround:

Manually set Heap Size
Modify Tomcat_home/bin/catalina.bat, add the following line to the "echo" Using catalina_base: $CATALINA _base "":

Copy Code code as follows:

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

or modify catalina.sh
In the "echo" Using catalina_base: $CATALINA _base "", add the following line:

Copy Code code as follows:

java_opts= "$JAVA _opts-server-xms800m-xmx800m-xx:maxnewsize=256m"
[HTML]

2, followed by: Java.lang.OutOfMemoryError:PermGen space

Reason:

PermGen space is the full name of permanent Generation spaces, refers to the permanent storage area of memory, this memory is mainly by the JVM storage class and meta information, class in the loader will be placed in the PermGen In space, it differs from the heap region of the class instance (Instance), and GC (garbage Collection) does not clean up permgen spaces during the runtime of the main program, so if you have a class in your application, PermGen space errors are most likely to occur when the Web server makes pre compile for JSPs. If your web app uses a large number of third-party jars that are larger than the JVM default size (4M), this error message is generated.

Workaround:

1. Manually Set MaxPermSize size
Modify Tomcat_home/bin/catalina.bat (under Linux for catalina.sh), in
[Code]
"Echo" Using catalina_base: $CATALINA _base "" Add the following line:
Set java_opts=%java_opts%-server-xx:permsize=128m-xx:maxpermsize=512m

Catalina.sh under:

Copy Code code as follows:

java_opts= "$JAVA _opts-server-xx:permsize=128m-xx:maxpermsize=512m"

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.