Modify Tomcat memory size (Java. Lang. outofmemoryerror: Java heap space)

Source: Internet
Author: User
By default, Tomcat can use 128 MB of memory. In large application projects, this memory is not enough. If it is mild, the system performance will drop sharply

When it is heavy, the system cannot run, which affects the system stability. When the memory is insufficient, the common problem is to report the Tomcat memory benefit error.

The user package is 500 incorrect. The solution is to increase Tomcat's available memory and increase the memory usage in the program. Therefore, according to the application requirements,

It is necessary to adjust the JVM memory usage. Now we will list the methods and precautions for manually modifying Tomcat memory:

Tomcat provides two installation modes: installation free (*. Zip) and installation (*. EXE. Modify the Tomcat memory size for different installation methods

Precautions ):

Method 1 (free of installation (*. Zip): When you select the installation method, you can set the size of Tomcat initialization memory during tomcat installation. However, if

No choice during installation, or the application has changed. How can this problem be solved when Tomcat memory needs to be increased? At this point, we need to manually modify some Tomcat files.

After reading a lot of online materials, I used to modify the content of the <catalina_home> bin \ Catalina. BAT file. That is, I added a line of code in it:

Set java_opts =-xms512m-xmx512m // indicates that the minimum available memory for initialization and the maximum available memory are both 512 MB (modify the corresponding value)

For example, in Catalina. bat

Rem ----- execute the requested command
Echo using catalina_base: % catalina_base %
Echo using catalina_home: % catalina_home %
Echo using catalina_tmpdir: % catalina_tmpdir %
Echo using java_home: % java_home %

This column is changed

Rem ----- execute the requested command
Set java_opts =-xms512m-xmx512m
Echo using catalina_base: % catalina_base %
Echo using catalina_home: % catalina_home %
Echo using catalina_tmpdir: % catalina_tmpdir %
Echo using java_home: % java_home %

You can allocate a memory of 508.0625mb to the Java VM!

However, after modification, many people find that the modification does not take effect. That is, when Tomcat is started through the windows service, the actual memory is still default. The modified settings

It does not work, but it is effective to start through <catalina_home> bin \ Startup. bat. Why? Because during the installation process, the JVM

The initialization parameters of have already been written in the registry. Because the relevant parameters in the Registry have not been modified, the modifications were not made during Windows Service startup.

Effect. The <catalina_home> bin \ Startup. BAT file is directly used for startup through the configuration in the <catalina_home> bin \ Catalina. BAT file.

You need to reload it to the system service to take effect, or you can manually find and modify the startup value in the registry. The parameter has been configured when it is loaded to the service.

, Modifying startup. bat by yourself does not change the parameter settings in the registry.

Solution:
Method 1: Modify parameters in the Registry and add JVM initialization memory parameters:

Hkey_local_machinesoftwareapache software foundationtomcat service managertomcat5parametersjavaoptions

The value is

-Dcatalina. Home = "C: apachegrouptomcat 5.0"
-Djava. endorsed. dirs = "C: apachegrouptomcat 5.0 commonendorsed"
-Xrs

For example, add-xms512m-xmx800m

Method 2: Start With bin \ Startup. bat
First, configure the environment variable
After the preceding environment variables are configured, the values of the system variables are as follows:
Java_home: C: \ Program Files \ Java \ jdk1.5.0 _ 06
Catalina_home: D: \ jakarta-tomcat-5.0.30
Classpath:.; % java_home % \ Lib; % catalina_home % \ common \ Lib;
Path: % java_home % \ bin; % catalina_home % \ bin; % SystemRoot % \ system32; % SystemRoot %; %
SystemRoot % \ system32 \ WBEM
Then you can start it through bin \ Startup. bat

 

Method (2 installation (*. EXE): For installation-free users, you can also register Tomcat as a service for Windows:

Make other modifications to the service. BAT file so that Tomcat can better meet our requirements for different needs:
Go to Start-find configure Tomcat under Tomcat select Java in the control window and enter 256 in initial memory pool, maximum

Memory Pool: 512

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.