Java error handling: Java. Lang. outofmemoryerror: Java heap Space

Source: Internet
Author: User
Tags xms
Author: Xiaolou
Original Website: Http://blog.vonno.com/33993/viewspace_1245

17:50:57/personal classification: Knowledge Summary

Cause:
An exception occurs when a Java program is used to query 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 JVM can allocate 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.
Solution:
In tomcat_home/bin, add:
Set java_opts = % java_opts %-xms128m-xmx512m

 

Java. Lang. outofmemoryerror: Java heap Space
An exception occurs when a Java program is used to query 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 JVM can allocate 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 too small, in addition to the exception information, the response speed of the program will also be slow. 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.