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 '