Problem:
Run the Java program in Eclipse and go back to more than 1 million of the data to report the following error:
Java.lang.OutOfMemoryError:Java Heap Space
Exception Reason:
This exception information is thrown in the JVM if 98% of the time is used for GC and the available HEAP size is less than 2%.
The JVM heap setting is the set of memory space that the JVM can provision in the course of running the Java program. The JVM automatically sets the value of the heap size when it starts, and its initial space (that is,-XMS) is the 1/64 of physical memory, and the maximum space (-XMX) is the area of physical memory. You can use options such as the-XMN-XMS-XMX provided by the JVM to set it up.
For example: java-xmx3550m-xms3550m-xmn2g-xss128k
-xmx3550m: Sets the maximum available memory for the JVM to 3550m.
-xms3550m: Set the JVM initial memory to 3550m. This value can be set to the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes.
-XMN2G: Set the young generation size to 2G. The entire JVM memory size = younger generation size + old generation size + persistent generation size. The average fixed size for durable generations is 64m. The entire heap size = younger generation size + old generation size. Therefore, increasing the younger generation will reduce the size of older generations. This value has a large impact on system performance, and Sun's official recommendation is 3/8 for the entire heap.
-xss128k: Sets the stack size for each thread. After JDK5.0, each thread has a stack size of 1M, before each thread has a stack size of 256K. The size of the memory required for the more applied threads to be adjusted. In the same physical memory, reducing this value can generate more threads. However, the operating system of the number of threads within a process is still limited, can not be generated indefinitely, the empirical value of 3000~5000 around.
Solution:
Programme one:
The JVM size can be set in the Eclipse startup parameters because the Eclipse runtime also requires the JVM. The JVM size set in Eclipse.ini is not the size of the JVM used by a particular program to run, and is valid for all programs.
So how can you set the JVM size of a program?
(Of course, the console runs without this problem, such as: java-xms256m-xmx1024m classname, so you can set the JVM size of the current program)
The default JVM configuration for Eclipse is:-xms8m-xmx128m, which needs to be manually adjusted when the memory is low.
The specific setup methods are:
Select the class being run, click on the menu ' Run->run configurations ', select (x) =argument tab under the VM Arguments box to enter
-xms64m-xmx512m (depending on the size of your physical memory), save the operation is OK
Scenario Two:
The root of the problem is that the JVM virtual machine default heap size is 64M and can be achieved by setting its maximum and minimum values. The main ways to set this are:
1. You can change the system environment variable plus java_opts=-xms64m-xmx512m in Windows.
2. If Tomcat is used,
1) Under Windows, you can add the following in the C:\tomcat5.5.9\bin\catalina.bat: set java_opts=-xms64m-xmx256m,
position in: REM Guess catalina_home if not defined the line below plus fit.
2) under Linux, in front of {tomcat_home}/bin/catalina.sh, add set java_opts= '-xms64-xmx512 '.
Eclipse Error: Java.lang.OutOfMemoryError:Java heap Space