Java memory overflow mainly involves two exceptions: heap memory overflow and non-heap memory overflow.
1. java. Lang. outofmemoryerror: Java heap space. Heap size settings
The JVM heap setting refers to the setting of memory space that can be provisioned by JVM during Java program running. The JVM automatically sets heap 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. The-xmn-XMS provided by JVM can be used
-Xmx and other options can be set. The heap size is young generation and tenured generaion.
. Tip: if 98% is used for GC and the available heap size is less than 2% in JVM, this exception is thrown. Tip: heap size
A maximum of 80% of the available physical memory is required. Generally, the-XMS and-xmx options must be set to the same option to reduce the performance loss caused by the JVM's continuous memory expansion.
-Xmx value.
Solution: manually set the heap size,-xms1024m-xmx1024m-xmn256m
2. java. Lang. outofmemoryerror: permgen space. The full name of permgen space is permanent generation space, which refers to the permanent storage area of the memory. This memory is mainly used by JVM to store class and meta information, when a class is loaded, it will be placed in the permgen space. It is different from the heap region where the class instance is stored. GC (garbage collection) permgen space is not cleaned up during the main program running period. Therefore, if your application contains many classes, the permgen space error may occur, this error is common when the web server pre-compile the JSP. If your web app uses a large number of third-party jar files and the size exceeds the default JVM size (4 MB), this error message is generated.
Solution: manually set the maxpermsize. Add "-XX: maxpermsize = m" to the Java startup parameters. In the startup parameters, the persistent generation size should not be too large.
Suggestion: Move the same third-party jar files to the common lib directory of the application server to reduce the memory usage of jar files.