Increase Tomcat java memory

Source: Internet
Author: User
Tags xms

/First check whether the program has an infinite loop Restriction

This problem is mainly caused by Java. Lang. outofmemoryerror: Java heap space. After such a problem occurs for the first time, it causes other problems. Check on the Internet may be the reason why Java's stack settings are too small.
There are two solutions to this problem:
1. Set Environment Variables

Solution: manually set heap size
Modify tomcat_home/bin/Catalina. Sh
Set java_opts =-xms32m-xmx512m
You can change the memory of your machine.

2. Java-xms32m-xmx800m classname
This parameter is added when the Java class file is executed. classname indicates the class name to be executed. (Including package name)
This solves the problem. In addition, the execution speed is much faster than when no setting is made.

If you may use eclispe during the test, you need to enter the-xms32m-xmx800m parameter in the VM arguments in eclipse-> Run-arguments.

Later, the startup parameter was modified in eclilpse and-xms32m-xmx800m was added to the VM arguments to solve the problem.

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"

For a large web project, the memory space allocated by Tomcat by default cannot be started. If you do not start Tomcat in myeclipse, you can set Tomcat as follows:

Tomcat_home/bin/Catalina. Bat adds the following sentence:

 

Set java_opts =-xmx1024m-xms512m-XX: maxpermsize = 256 m

If you want to start it in myeclipse, the above modification will not work. You can set it as follows:

Myeclipse-> preferences-> myeclipse-> servers-> tomcat-> Tomcat ×. ×-> In the JDK panel

Add-xmx1024m-xms512m-XX: maxpermsize = 256 m to optional Java VM arguments.

The above is the post, but the problem I encountered is: when starting tomcat in myeclipse, the prompt "Ava. Lang. outofmemoryerror: Java heap space" is displayed. The solution is:

Myeclipse-> preferences-> myeclipse-> servers-> tomcat-> Tomcat ×. ×-> In the JDK panel

Add-xmx1024m-xms512m-XX: maxpermsize = 256 m to optional Java VM arguments.

 

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.