Tomcat launch times Java.lang.OutOfMemoryError:Java Heap space

Source: Internet
Author: User
Tags xms

The workaround is as follows:

Modify the JVM-initiated parameters in MyEclipse open myeclipse-->windows-->preference-->myeclipse->server-> Find the JDK under Tomcat set the startup parameters in the text box-xms168m-xmx512m

Second, Java.lang.OutOfMemoryError:Java heap space
Heap Size Setting
The JVM heap setting is the set of memory space that the JVM can provision during the run of the Java program. The JVM automatically sets the value of heapsize when it is started.
Its initial space (that is,-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
To set. The size of 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 used for GC and the available heap size is less than 2%.
Tip: The Heap size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4.
Workaround: Manually set the heap size

The root cause of this problem is that the default heap size of the JVM virtual machine is 64M, which can be achieved by setting its maximum and minimum values. The method of setting is mainly several.

1. You can change the system environment variables in Windows
Plus java_opts=-xms64m-xmx512m.

2, if using Tomcat, under Windows, you can

C:/tomcat5.5.9/bin/catalina.bat? In addition:

Set java_opts=-xms64m-xmx256m

Position in: REM Guess catalina_home if not defined? This line is suitable for the following.

3. If it is a Linux system
Linux in front of {tomcat_home}/bin/catalina.sh, plus
Set java_opts= '-xms64-xmx512 '

I have tested the previous exception to start Tomcat with MyEclipse after adding set java_opts=-xms64m-xmx256m in the Catalina.bat file under the Tomcat installation directory bin. Check the information before you know:
Tomcat offers two installation modes, the free Install (*.zip) and the installation (*.exe). How to modify Tomcat memory size for different installation methods several considerations (Windows environment):
Mode 1: When you choose the installation method, you can set the TOMCAT init memory size during the installation of Tomcat. But what if there is no choice at the time of installation, or if the application changes, how much does it take to increase tomcat memory? At this point, we have to manually modify some of the Tomcat files: read a lot of online information, are said to modify the contents of the/bin/catalina.bat file, that is, add a line of code: set java_opts=-xms512m-xmx512m//expression Initialize the minimum available memory and the maximum available memory is 512MB (modify the corresponding value) as in the Catalina.bat
REM-----Execute The requested Command---------------------------------------
echo usingcatalina_base:? Talina_base%
echo usingcatalina_home:? Talina_home%
echo Using catalina_tmpdir:? talina_tmpdir%
echo Usingjava_home:%java_home%
This column should read
REM-----Execute The requested Command---------------------------------------
Set java_opts=-xms512m-xmx512m
echo usingcatalina_base:? Talina_base%
echo usingcatalina_home:? Talina_home%
echo Usingcatalina_tmpdir:? talina_tmpdir%
echo Usingjava_home:%java_home%
You can allocate a Java virtual machine to 508.0625MB of memory!
But a lot of people modified and found that the changes did not work, that is, the Windows service to start Tomcat, the actual memory is still the default, the modified settings do not work, and through the/bin/startup.bat boot is effective. What is this for? Because the initialization parameters of the JVM are already written in the registry during the installation process, the modifications do not take effect when the Windows service is started because the parameters in the registry are not modified. The boot through/bin/startup.bat is configured directly through the/bin/catalina.bat file. You need to reload into the system service to take effect, or you manually find the registry to modify the startup value, loaded into the service when the parameters have been configured, their own modification of artup.bat will not change the parameters in the registry settings. Workaround: Modify the parameters in the registry to include the JVM initialization memory parameters: Hkey_local_machine/software/apache software foundation/tomcatservice MANAGER/TOMCAT5 /parameters/javaoptions
Value is
-dcatalina.home= "C:/apachegroup/tomcat 5.0"
-djava.endorsed.dirs= "C:/apachegroup/tomcat5.0/common/endorsed"
-xrs
If you join-xms512m-xmx800m
Mode 2:For users who are not installing, you can also do this by registering Tomcat as a service for Windows: too cumbersome or not in this way.

Third, Java.lang.OutOfMemoryError:PermGen space

The full name of PermGen space is permanent Generation space, which refers to the permanent storage area of memory,
This memory is primarily stored by the JVM with class and meta information, and class is placed in PermGen space when it is loader.
Unlike the heap area where the class instance (Instance) is stored, the GC (garbage Collection) does not operate on the main program
PermGen space for cleanup, so if you have a lot of classes in your app, you're likely to have permgen space errors,
This error is common when the Web server pre-compile the JSP. If you use a large number of third-party jars under your web app, its size
The default size of the JVM (4M) is exceeded, and this error message is generated.
Workaround: Manually set the MaxPermSize size

Modify Tomcat_home/bin/catalina.bat
Add the following line to the "echo" Using catalina_base: $CATALINA _base "":
Java_opts= "-server-xx:permsize=64m-xx:maxpermsize=128m
Recommendation: Move the same third-party jar files to the Tomcat/shared/lib directory, which can reduce the memory consumption of the jar document.


It is also recommended to modify the JVM startup parameters in MyEclipse OK

Tomcat launch times Java.lang.OutOfMemoryError:Java Heap space

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.