Solution to Tomcat outofmemoryerror

Source: Internet
Author: User
Tags xms

 

1. First, java. Lang. outofmemoryerror: Java heap Space

 

Explanation:

 

Heap size settings

 

JVM heap setting refers to the setting of 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.

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. BAT and add the following lines to & ldquo; echo & quot; using catalina_base: $ catalina_base & quot; & rdquo:

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

 

Or modify Catalina. Sh.
Add the following lines to & ldquo; echo & quot; using catalina_base: $ catalina_base & quot; & rdquo:
Java_opts = & quot; $ java_opts-server-xms800m-xmx800m-XX: maxnewsize = 256 M & quot;

 

2. Followed by: Java. Lang. outofmemoryerror: permgen Space

 

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 will not be 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 in the web server pre-processing JSP.
Compile. 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 in Linux. SH), add the following lines to & ldquo; echo & quot; using catalina_base: $ catalina_base & quot; & rdquo:

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

 

Catalina. sh:
Java_opts = & quot; $ java_opts-server-XX: permsize = 128 M-XX: maxpermsize = 512 M & quot;

 

I also saw another post and thought it was quite good. The excerpt is as follows:
Analysis of Java. Lang. outofmemoryerror: permgen Space

 

Many people found that the problem was caused by spring, hibernate, and tomcat. They dynamically generated classes, resulting in permanent Heap Overflow in JVM. 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.

 

But the question is, why is the open source of these trump cards having the same problem? Is it a more basic reason? Tomcat answers this question in a vague manner in Q & amp; A. We know this question, but this question is generated by a more basic question.

 

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!

 

The most thorough solution to this bug is to use sun's JDK instead of BEA's jrokit.

 

For the above two problems, my solution is:

 

Add the following in the first line of Catalina. BAT:
Set java_opts =-xms64m-xmx256m-XX: permsize = 128 M-XX: maxnewsize = 256 m-XX: maxpermsize = 256 m

 

Add the following in the first line of Catalina. sh:
Java_opts =-xms64m-xmx256m-XX: permsize = 128 M-XX: maxnewsize = 256 m-XX: maxpermsize = 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.