java.lang.OutOfMemoryError error collation and resolution

  • 2020-05-10 18:07:35
  • OfStack

java.lang.OutOfMemoryError handles errors

java.lang.OutOfMemoryError exception resolution

Reasons: the following are common:

1. The amount of data loaded in memory is too large, for example, too much data is extracted from the database at one time;

2. There is a reference to the object in the collection class, which is not emptied after use, so JVM cannot be recycled;

3. There are dead loops in the code or object entities with too many repetitions generated by loops;

4. BUG in the third party software used;

5. The memory value of startup parameter is set too small;

Common errors: 1. tomcat: java lang. OutOfMemoryError: PermGen space

2.tomcat:java.lang.OutOfMemoryError: Java heap space

3.weblogic:Root cause of ServletException java.lang.OutOfMemoryError

4.resin:java.lang.OutOfMemoryError

5.java:java.lang.OutOfMemoryError

To solve; 1. Application server prompts for error resolution: set the boot parameter memory value sufficiently large.

2. Resolution of errors caused by Java code:

1) check your code for dead loops or recursive calls.

2) check whether there is a large loop that generates new object entities repeatedly.

3) check whether there is a query to get all the data once in the database query. 1 in general, if 100, 000 records are taken to memory at a time, memory overflow may occur. This problem is relatively hidden. Before going online, there is less data in the database, so it is not easy to have a problem. After going online, there is more data in the database, and one query may cause memory overflow. Therefore, database queries should be paginated as much as possible.

4) check whether collection objects such as List and MAP are not cleared after use. Collection objects such as List, MAP, and so on will always have references to the objects so that they cannot be recycled by GC.

Case: 1. When hibernate queried data, he queried too much data at one time. Later, he adjusted the code of this part and only took out a specified amount of data at a time, which successfully solved the problem. 2. When doing the stress test, OutOfMemoryError appears and it is found that the resource 1 of session has not been released. It is better to release the resource of session through invalidate() method of session. 3. There is a dead loop in the program. 4. OutOfMemoryError occurs in tomcat deployment and operation. Increase the memory parameter value to solve this problem.

tomcat java.lang.OutOfMemoryError: Java heap space exception handling

The setting of Heap size JVM heap refers to the memory space that JVM can allocate during the operation of java program.JVM will automatically set the value Heap size at startup, with the initial space (i.e. -Xms) being 1/64 of the physical memory and the maximum space (-Xmx) being 1/4 of the physical memory. You can set this using options such as -Xmn-Xms-Xmx provided by JVM. The size of Heap size is the sum of Young Generation and Tenured Generaion. Tip: in JVM this exception message is thrown if 98% of the time is spent on GC and less than 2% of Heap size is available. Tip: Heap Size should not exceed 80% of the available physical memory at most. For 1, set the -Xms and -Xmx options to the same, while -Xmn is 1/4 of the -Xmx value.

2. Solution: manually Heap size modify TOMCAT_HOME/bin/catalina sh in "echo" Using CATALINA_BASE:     $CATALINA_BASE "" above to join the following line: JAVA_OPTS=" -server-Xms800m-Xmx800m    -XX :MaxNewSize=256m"

tomcat java.lang.OutOfMemoryError: PermGen space exception handling

1. The full name of PermGen space PermGen space is Permanent Generation space, which refers to the permanent storage area of memory. This memory is mainly used for JVM to store Class and Meta information. GC(Garbage Collection) does not clean up PermGen space during the main program run time, so if you have a lot of CLASS in your application, you are more likely to have an PermGen space error, which is common when pre compile server is doing pre compile. This error message will be generated if your WEB APP USES a large number of third party jar and its size exceeds the default size for jvm (4M).

Solution: manually modify TOMCAT_HOME MaxPermSize size/bin/catalina sh in "echo" Using CATALINA_BASE:     $CATALINA_BASE "" above to join the following line: JAVA_OPTS=" -server-PermSize = 64M-XX =128m recommendation: move the same third jar file to tomcat/shared/lib to reduce the repeated memory usage of jar documents.

weblogic java.lang.OutOfMemoryError exception handling

Error: "Root cause of ervletException java lang OutOfMemoryError"

Solutions: Adjust bea/weblogic/common CommEnv parameters :sun if "%PRODUCTION_MODE%" == "true" goto prod_mode JAVA_VM= -client set MEM_ARGS= -Xms256m-Xmx512m_OPTIONS =% JAVA_goto continue JAVA_VM= -server set MEM_ARGS= -Xms256m-Xmx512m-XX :MaxPermSize=256m goto continue

java.lang.OutOfMemoryError: PermGen space exception handling when Eclipse runs Jboss

java.lang.OutOfMemoryError: PermGen space when running Jboss in Eclipse, the time is too long and sometimes the java.lang.OutOfMemoryError: PermGen space error may occur. Here is a solution:

1) click the small arrow next to the debug icon;

2) click "Debug Configurations..." Menu item;

3) select "Generic Server" on the left under "JBoss v4.2 at localhost";

4) click the "Arguments" Tab TAB on the right and add in "VM arguments" :

-Dprogram.name=run.bat -Djava.endorsed.dirs="D:/JBoss405/bin/../lib/endorsed" -Xms128m -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=256m

5) if you are running JBoss in command line mode or by clicking "run.bat", you will have to modify the JVM option in bin/ run.conf =" -Xms128m-Xmx512m..." This 1 paragraph, and then after that add "-XX :PermSize= 64m-XX :MaxPermSize=256m". Save it for OK.

6) note: the Numbers 128, 512, 64 and 256 can be adjusted according to the configuration of the machine, and then click "Apply".

Resin java lang OutOfMemoryError exception handling

Reason: this error occurs because JVM physical memory is too small. The default Java virtual machine has a maximum memory of only 64 megabytes, which is probably fine during development and debugging, but far from sufficient in a real-world application environment, unless your application is very small and has little traffic. Otherwise you may find an error with the package java.lang.OutOfMemoryError after the program has been running for 1 period. So we need to increase the size of virtual machine memory available for resin.

Solution: modify/usr/local/resin/bin/httpd sh args options in the add parameters - Xms (initial memory) and - Xmx (maximum can use memory size) can be used to restrict JVM physical memory usage. For example: args=" -Xms128m-Xmx256m ", JVM has an initial physical memory of 128m and a maximum physical memory of 256m. These two values should be set by the system administrator based on the actual situation of the server.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: