Java.lang.OutOfMemoryError:Java Heap Space Solution

Source: Internet
Author: User
Tags xms

Java.lang.OutOfMemoryError:Java Heap Space Solution Blog Category:
    • Java
Javatomcatmyeclipsejvmwindows

First check that the program has no limit to the dead loop.
This problem is mainly caused by the problem Java.lang.OutOfMemoryError:Java heap space. The first time such a problem arises, other problems are raised. A search on the web may be the reason why Java's stack settings are too small.
According to the answers on the Internet, there are basically two ways to solve this problem:
1. Setting Environment variables

Workaround: Manually set the heap size
Modify Tomcat_home/bin/catalina.sh
Set java_opts=-xms32m-xmx512m
Can be changed according to the memory of your machine.

2, java-xms32m-xmx800m ClassName
is to add this parameter when executing the Java class file, where ClassName is required to perform the real class name. (including package name)
This solves the problem. And the speed of execution is much faster than when it is not set.

If you can use Eclispe at the time of testing, you will need to enter-xms32m-xmx800m This parameter in the VM arguments in Eclipse->run-arguments.

The startup parameters were later modified in Eclilpse, and the-xms32m-xmx800m was added to the VM arguments to solve the problem.

One, 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.sh
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.

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 the heap size 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
Modify Tomcat_home/bin/catalina.sh
Add the following line to the "echo" Using catalina_base: $CATALINA _base "":
Java_opts= "-server-xms800m-xmx800m-xx:maxnewsize=256m"

example, the following gives a reference to the parameter setting of the Java JVM in the 1G memory environment:

Java_opts= "-server-xms800m-xmx800m-xx:permsize=64m-xx:maxnewsize=256m-xx:maxpermsize=128m-djava.awt.headless= True "

A large Web project, the default allocated memory space with Tomcat cannot be started, and if not started in MyEclipse Tomcat can be set for Tomcat:

Add such a sentence in Tomcat_home\bin\catalina.bat:



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

If you want to start in MyEclipse, the above modifications will not work, and can be set as follows:

In the MYECLIPSE->PREFERENCES->MYECLIPSE->SERVERS->TOMCAT->TOMCATX.X->JDK panel

Optional Java VM arguments added:-xmx1024m-xms512m-xx:maxpermsize=256m

The above is the repost, but I met the problem is: in MyEclipse start Tomcat, prompted "Ava.lang.OutOfMemoryError:Java heap space", the solution is:

In the MYECLIPSE->PREFERENCES->MYECLIPSE->SERVERS->TOMCAT->TOMCATX.X->JDK panel

Optional Java VM arguments added:-xmx1024m-xms512m-xx:maxpermsize=256m

It's very spiritual.
---------------------------------------------------------
Tomcat Boot Memory settings
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
example, the following gives a reference to the parameter setting of the Java JVM in the 1G memory environment:
Java_opts= "-server-xms800m-xmx800m-xx:permsize=64m-xx:maxnewsize=256m-xx:maxpermsize=128m-djava.awt.headless= True "
Java_opts= "-SERVER-XMS768M-XMX768M-XX:PERMSIZE=128M-XX:MAXPERMSIZE=256M-XX:
Newsize=192m-xx:maxnewsize=384m "
Catalina_opts= "-server-xms768m-xmx768m-xx:permsize=128m-xx:maxpermsize=256m
-xx:newsize=192m-xx:maxnewsize=384m "
Linux:
Catalina.sh in the/usr/local/apache-tomcat-5.5.23/bin directory
Added: java_opts= '-xms512m-xmx1024m '
The "M" description is MB, otherwise it is KB and will be reported out of memory when starting Tomcat.
-XMS: Initial value
-XMX: Maximum Value
-XMN: Minimum value
Windows
Join at the front of the Catalina.bat
Set java_opts=-xms128m-xmx350m
If the Tomcat,ok setting is in effect with Startup.bat startup. Enough to allocate 200M of memory successfully.
However, if you do not execute startup.bat to start Tomcat but use Windows system services to start the Tomcat service, the settings above will not take effect.
This means that set java_opts=-xms128m-xmx350m does not work. Allocate 200M of memory above to Oom.
The Windows service performs bin\tomcat.exe. He reads the value in the registry instead of the Catalina.bat setting.
Workaround:
Modify the registry Hkey_local_machine\software\apache software Foundation\tomcat Service manager\tomcat5\parameters\javaoptions
The original value is
-dcatalina.home= "C:\ApacheGroup\Tomcat 5.0"
-djava.endorsed.dirs= "C:\ApacheGroup\Tomcat 5.0\common\endorsed"
-xrs
Join-xms300m-xmx350m
Restart Tomcat service, set to take effect



==================================================================





Tomcat as a parameter configuration for Windows services, especially for permsize settings
When Tomcat starts with Startup.bat, the parameters are set online, which is no longer described here.

When Tomcat as a system service windows, the Internet to find a lot of relevant articles, there is no more comprehensive parameter setting method, generally explained the XMS and XMX settings, have not provided other parameters of the description, not practical enough. After the research and trial of Procrun under Apache, it is clear that the general parameter setting method. In fact, Tomcat5.exe itself already contains the function of Procrun, this is a lot of people on the Internet can not find Procrun.exe file download reason.
Procrun can refer to: http://commons.apache.org/daemon/procrun.html
Note: Using TOMCAT5 as an example, this should apply equally to tomcat6.

Instead of using the registry, we use the GUI tools provided by Tomcat to set it up.
1, under the command line execution: Tomcat5w.exe//es//tomcatservice
Where Tomcatservice is the name of the Windows service you are joining. In this way, a Tomcat service manager appears on the Windows taskbar, with the following icon.
2. Open the Tomcat Service Manager's Java page, as

Enter the parameters you want to set in the Java options, such as setting permsize memory
-xx:permsize=64m
-xx:maxpermsize=192m
-xx:reservedcodecachesize=48m
-duser.timezone=gmt+08
Note: There are no spaces behind each line.
Similarly, we can also make modifications in the registry, Hkey_local_machine\software\apache software Foundation\procrun 2.0\testservice\parameters\java

This article is reproduced, I tried the above said method:

If you want to start in MyEclipse, the above modifications will not work, and can be set as follows:

In the MYECLIPSE->PREFERENCES->MYECLIPSE->SERVERS->TOMCAT->TOMCATX.X->JDK panel

Optional Java VM arguments added:-xmx1024m-xms512m-xx:maxpermsize=256m

Really effective, solve java.lang.OutOfMemoryError:Java heap space memory overflow problem!!

Thanks for sharing!

Java.lang.OutOfMemoryError:Java Heap Space workaround

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.