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 ".