Perfect solution for Java Lang.outofmemoryerror handling errors

Reasons: the following are common:

1. The amount of data loaded in the memory is too large, such as taking 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, so that the JVM cannot recycle;

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

4. Bugs in the third-party software used;

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

Common error tips:

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

solve:

1. Solution to the error prompted by the application server: set the memory value of the startup parameter large enough.

2. Troubleshooting of errors caused by java code: focus on the following points:

1) Check the code for dead loops or recursive calls.

2) Check whether a large loop repeats to produce a new object entity.

3) Check whether there is a query to obtain all data at one time in the database query. Generally speaking, if 100000 records are taken to memory at a time, it may cause memory overflow. This problem is hidden. Before going online, there is less data in the database, which is not easy to cause problems. After going online, there is more data in the database, and one query may cause memory overflow. Therefore, for database query, paging query shall be adopted as far as possible.

4) check whether the list, map and other collection objects have problems that have not been cleared after use. List, map and other collection objects always have references to objects, so that these objects cannot be recycled by GC.

Case:

1. When hibernate queries data, it queries too much data at one time. Later, it adjusts the code of this part and only takes out the specified amount of data each time to successfully solve the problem. 2. During the stress test, outofmemoryerror appears. It is found that the session resources have not been released. It is best to release the session resources through the session invalidate() method.

3. Dead cycle occurs in the program.

4. Outofmemoryerror occurs in Tomcat deployment and operation. Increase the memory parameter value to solve this problem.

Java. In Tomcat Lang.outofmemoryerror: Java heap space exception handling

1、 Heap size JVM heap setting refers to the setting of memory space that the JVM can allocate during Java program running When the JVM starts, it will automatically set the heap size value. 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. Heap size is the sum of young generation and tenured generation. Tip: in the JVM, if 98% of the time is used for GC and the available heap size is less than 2%, this exception message will be thrown. Tip: the maximum heap size should not exceed 80% of the available physical memory. Generally, set the - XMS and - Xmx options to the same, and - XMN to the - Xmx value of 1 / 4.

2、 Solution: manually set heap size and modify Tomcat_ HOME/bin/catalina. SH add the following line above "echo" using catalina_base: $catalina_base ": Java_ OPTS="-server -Xms800m -Xmx800m -XX:MaxNewSize=256m"

Java. In Tomcat Lang.outofmemoryerror: 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 used by the JVM to store class and meta information. When class is loaded, it will be placed in permgen space. It is different from the header area where class instances are stored. GC (garbage collection) will not clean up permgen space during the running of the main program, Therefore, if there are many classes in your application, there is likely to be a permgen space error, which is common when the web server pre compiles JSPS. If a large number of third-party jars are used under your web app, and their size exceeds the JVM default size (4m), this error message will be generated.

Solution: manually set the maxpermsize size and modify Tomcat_ HOME/bin/catalina. SH add the following line above "echo" using catalina_base: $catalina_base ": Java_ Opts = "- server - XX: permsize = 64M - XX: maxpermsize = 128M suggestion: move the same third-party jar file to Tomcat / shared / lib directory, so as to reduce the repeated memory occupation of jar documents.

Java. Net in Weblogic Lang.outofmemoryerror exception handling

Error prompt: "root cause of ervletexception Java. Lang. outofmemoryerror"

Solution: adjust the parameter in commonv in bea / Weblogic / common: sun if "% production_mode%" = = "true" goto sun_ prod_ mode   set JAVA_ VM=-client   set MEM_ ARGS=-Xms256m -Xmx512m -XX:MaxPermSize=256m   set JAVA_ OPTIONS=%JAVA_ OPTIONS% -Xverify:none   goto continue   :sun_ prod_ mode   set JAVA_ VM=-server   set MEM_ ARGS=-Xms256m -Xmx512m -XX:MaxPermSize=256m   goto continue

When eclipse runs JBoss, Java Lang. outofmemoryerror: permgen space exception handling

When running JBoss in eclipse, it takes too long, and sometimes Java. Java Lang. outofmemoryerror: error in permgen space. Here is a solution:

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

2) Click "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 add the following 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 should run JBoss in bin / run. Bat The JVM option has been modified in the conf file. Find Java_ Opts = "- xms128m - xmx512m..." and then add "- XX: permsize = 64M - XX: maxpermsize = 256M" after it. Save it.

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

Java. Java under resin Lang.outofmemoryerror exception handling

Cause: this error usually occurs because the JVM physical memory is too small. The maximum memory of the default Java virtual machine is only 64 megabytes, which may not be a problem in the process of 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 after the program runs for a period of time, the package Java Error in lang.outofmemoryerror. Therefore, we need to increase the size of virtual machine memory available for resin.

Solution: modify / usr / local / resin / bin / httpd The args option in SH adds parameters - XMS (initial memory) and - Xmx (maximum available memory size) to limit the JVM's physical memory usage. For example, after args = "- xms128m - xmx256m" is set, the JVM's initial physical memory is 128M and the maximum available physical memory is 256M. These two values should be set by the system administrator according to the actual situation of the server.

The above is the perfect solution Java Lang. outofmemoryerror handles all the contents of the error problem. I hope you can support more programming tips~

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>