Home > 类库下载 > java类库 > java.lang.OutOfMemoryError handling errors

java.lang.OutOfMemoryError handling errors

高洛峰
Release: 2016-10-09 09:01:49
Original
1525 people have browsed it

Causes: Common ones include the following:

1. The amount of data loaded in the memory is too large, such as retrieving too much data from the database at one time;

2. There are references to objects in the collection class, which are not cleared after use. , making the JVM unable to recycle;

3. There is an infinite loop in the code or the loop generates too many duplicate object entities;

4. BUG in the third-party software used;

5. The startup parameter memory value is set too much Small;

Common error prompts: 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

Solution; 1. Solution to application server prompt error: Set the startup parameter memory value to be large enough.

2. Solution to errors caused by Java code: Focus on the following points:

1) Check whether there are infinite loops or recursive calls in the code.

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

3) Check whether there is a query to obtain all the data at once in the database query. Generally speaking, if one hundred thousand records are fetched into the memory at one time, it may cause a memory overflow. This problem is relatively hidden. Before going online, there was less data in the database and it was less likely to cause problems. After going online, there was more data in the database, and a single query may cause memory overflow. Therefore, try to use paging for database queries.

4) Check whether collection objects such as List and MAP are not cleared after use. Collection objects such as List and MAP will always have references to the objects, making these objects unable to be recycled by GC.

Case: 1. When hibernate queries data, it queries too much data at one time. Later, the code of this part was adjusted, and only the specified amount of data was taken out each time, successfully solving the problem. 2. When doing stress testing, an OutOfMemoryError occurs and it is found that the session resources have not been released. It is best to release the session resources through the session's invalidate() method. 3. An infinite loop appears in the program. 4. OutOfMemoryError occurs when deploying and running tomcat. Increase the memory parameter value to solve this problem.

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

1. Heap size The setting of the JVM heap refers to the setting of the memory space that the JVM can allocate and use during the running of the java program. The JVM will automatically set the Heap size value when it starts. 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 the -Xmn -Xms -Xmx and other options provided by the JVM to set it. The size of Heap size is the sum of Young Generation and Tenured Generation. Tip: In the JVM, this exception message will be thrown if 98% of the time is used for GC and the available Heap size is less than 2%. Tip: The maximum Heap Size should not exceed 80% of the available physical memory. Generally, the -Xms and -Xmx options should be set to the same value, and -Xmn should be 1/4 of the -Xmx value.

2. Solution: Manually set the Heap size. Modify TOMCAT_HOME/bin/catalina.sh and add the following line to "echo "Using CATALINA_BASE: $CATALINA_BASE"": JAVA_OPTS="-server -Xms800m -Xmx800m -XX:MaxNewSize=256m "

java.lang.OutOfMemoryError in tomcat: PermGen space exception handling

1. PermGen space The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​​​memory. This memory is mainly stored by the JVM For Class and Meta information, Class will be placed in the PermGen space when it is loaded by Loader. It is different from the Heap area where class instances (Instances) are stored. GC (Garbage Collection) will not clean up the PermGen space during the running of the main program. , so if there are many CLASS in your application, PermGen space errors are likely to occur. This error is common when the web server pre-compiles JSP. If your WEB APP uses a large number of third-party jars, and their size exceeds the default size of the jvm (4M), this error message will be generated.

Solution: Manually set the MaxPermSize size and modify TOMCAT_HOME/bin/catalina.sh. Add the following line to "echo "Using CATALINA_BASE: $CATALINA_BASE"": JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory, so as to reduce the repeated memory usage of jar files. Tip: "Root cause of ervletException java.lang.OutOfMemoryError"

Solution: Adjust the parameters in CommEnv in bea/weblogic/common: sun if "%PRODUCTION_MODE%" == "true" goto sun_prod_mode set JAVA_VM=-client set MEM_ARGS = - 6m  goto continue

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

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

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

2) Click the "Debug Configurations..." menu item;

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

4) Click the "Arguments" tab on the right, and select " 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 run JBoss in command line mode or directly click "run.bat", then you need to modify the JVM options in the bin/run.conf file and find JAVA_OPTS=" -Xms128m -Xmx512m…” this paragraph, and then add “-XX:PermSize=64m -XX:MaxPermSize=256m” at the end. Save and it's OK.

6) Note: The numbers 128, 512, 64 and 256 can be adjusted according to the configuration of your machine, and then click "Apply".

Exception handling of java.lang.OutOfMemoryError under Resin

Cause: This error occurs usually because the JVM physical memory is too small. The default maximum memory of the Java virtual machine is only 64 MB, which may not be a problem during development and debugging, but it is far from meeting the needs in the actual application environment, unless your application is very small and has little access. Otherwise, you may find that a java.lang.OutOfMemoryError error occurs after the program has been running for a period of time. Therefore, we need to increase the size of the virtual machine memory available for resin.

Solution: Modify the args option in /usr/local/resin/bin/httpd.sh and add parameters -Xms (initial memory) and -Xmx (maximum usable memory size), which can be used to limit the physical memory usage of the JVM. For example: args="-Xms128m -Xmx256m" After setting, the initial physical memory of the JVM is 128m, and the maximum usable physical memory is 256m. These two values ​​​​should be set by the system administrator according to the actual situation of the server.

Reprinted from: http://www.cnblogs.com/cyjch/archive/2012/04/10/2440421.html


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template