Java. Lang. outofmemoryerror: Java heap Space Solution

Source: Internet
Author: User
Tags xms

The root cause of this problem is that the default heap size of the JVM virtual machine is 64 MB, which can be achieved by setting the maximum and minimum values. There are several ways to set the heap size.

1. You can add java_opts =-xms64m-xmx512m to change the system environment variable in windows.

2. If Tomcat is used, in windows, add: e: \ Program Files \ apache-Tomcat-6.0.29 \ bin \ Catalina. BAT:

Set java_opts =-xms512m-xmx512m

The location is added to the row REM guess catalina_home if not defined.

However, it seems that the error message does not work, and the JDK setting parameters in Tomcat 6. x of myeclipse are good. The parameters are as follows:

-Xms128m-xmx512m
-XX: permsize = 128 m
-XX: maxpermsize = 128 m

3. For a Linux System
Before {tomcat_home}/bin/Catalina. Sh, add

Set java_opts = '-xms512-xmx512'

Java. Lang. outofmemoryerror: Java heap Space
Use JavaProgramAn exception occurred when querying a large amount of data from the database:
Java. Lang. outofmemoryerror: Java heap Space
This exception is thrown if 98% is used for GC and the available heap size is less than 2% in JVM.

JVM heap setting refers to the setting of memory space that can be provisioned by JVM 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.
example: Java-jar-xmn16m-xms64m-xmx128m MyApp. jar
If the heap size is set to a small value, in addition to the exception information, the response speed of the program is also reduced. GC takes more time, and the execution time assigned by the application is less.
the heap size should not exceed 80% of the available physical memory. Generally, the-XMS and-xmx options must be set to the same, and-xmn is the-xmx value of 1/4.
the-XMS-xmn setting of heap size should not exceed the physical memory size. Otherwise, the system prompts "error occurred during initialization of VM cocould not reserve enough space for object Heap ".

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.