Javax.servlet.ServletException:Java Heap Space__java

Source: Internet
Author: User

An exception occurred when querying large amounts of data from a database using Java programs: Java.lang.OutOfMemoryError:Java heap Space
This exception information is thrown in the JVM if 98% of the time is for GC and the available HEAP size is less than 2%.

The JVM heap setting is the setting of the memory space that the JVM can allocate to the Java program while it is running. The JVM automatically sets the value of heap size when it starts, and its initial space (i.e.-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 set it up.
For example: java-jar-xmn16m-xms64m-xmx128m Myapp.jar
If the heap size setting is small, in addition to these exception information, you will find that the program's response speed slows down. The GC takes up more time and the application is allocated less execution time.
Heap Size is not greater than 80% of the available physical memory, generally to set the-XMS and-XMX options to the same, and-xmn to the-XMX value of 1/4.
The-XMS-XMN setting for Heap size does not exceed the physical memory size. Otherwise, the "Error occurred during initialization of VM could not reserve enough spaces for object heap" will be prompted.

The root 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 Main method is to set up a few.

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

2, if used Tomcat, under Windows, can be added in C:/tomcat5.5.9/bin/catalina.bat:
Set java_opts=-xms64m-xmx256m
Position in: REM Guess catalina_home if not defined the line below is appropriate.

3. If Linux system
linux  in front of {tomcat_home}/bin/catalina.sh, add set java_opts= '-xms64-xmx512 '  

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.