Java. lang. OutOfMemoryError

Source: Internet
Author: User
Tags xms

Java. lang. OutOfMemoryError

 

Cause:
The following are common examples:

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

2. There are references to objects in the Collection class, which are not cleared after use, so that JVM cannot be recycled;

3. There are endless loops or loops in the code that generate too many repeated object entities;

4. Bugs in third-party software used;

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


Common error messages:
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. How to Solve the error prompted by the Application Server:
Set the memory value of the startup parameter to large enough.

 

2. Solutions to errors caused by Java code:
Troubleshoot the following issues:

1) check whether there is an endless loop or recursive call in the code.

2) check whether there are large loops that repeatedly generate new object entities.

3) check whether all data is obtained once in the database query. Generally, if 100,000 records are retrieved to the memory at a time, memory overflow may occur. This problem is relatively hidden. Before going online, the database has less data and is not prone to problems. After going online, there is more data in the database, and a single query may cause memory overflow. Therefore, we recommend that you query the database by page.

4) Check whether List, MAP, and other collection objects are not 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 a time. Later, it adjusted the code of this Part to retrieve only the specified amount of data at a time, successfully solving this problem.
2. During the stress test, an OutOfMemoryError occurs. It is found that the resources of the session have not been released. It is best to release the resources of the session through the invalidate () method of the session.
3. An endless loop occurs in the program.
4. When an OutOfMemoryError occurs during tomcat deployment and running, increase the memory parameter value to solve this problem.

 

 

 

 

Java. lang. OutOfMemoryError: Java heap space Exception Handling in tomcat

I. Heap size
The JVM Heap setting refers to the setting of the memory space that JVM can allocate during the java program running. The JVM automatically sets the Heap size value 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. You can use options such as-Xmn-Xms-Xmx provided by JVM.
. The Heap size is the sum of 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: the Heap Size should not exceed 80% of the available physical memory. Generally, you must set the-Xms and-Xmx options to the same, and-Xmn to the-Xmx value of 1/4.


Ii. Solution: manually set Heap size
Modify TOMCAT_HOME/bin/catalina. sh
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: MaxNewSize = 256 m"

 

 

Java. lang. OutOfMemoryError: PermGen space Exception Handling in tomcat

I. PermGen space
PermGen space stands for Permanent Generation space, which is the Permanent storage area of the memory,
This memory is mainly used by JVM to store Class and Meta information. When the Class is loaded, it will be placed in PermGen space,
Unlike the Heap region of the storage Instance, GC (Garbage Collection) does not
PermGen space is cleaned up. 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
This error message is generated when the default jvm size (4 MB) is exceeded.

Solution: manually set the MaxPermSize
Modify TOMCAT_HOME/bin/catalina. sh
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "-server-XX: PermSize = 64 M-XX: MaxPermSize = 128 m
Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.

 

 

Java. lang. OutOfMemoryError Exception Handling in weblogic

Error message:
"Root cause of ervletException java. lang. OutOfMemoryError"

Solution:
Adjust the CommEnv parameter in bea/weblogic/common
: Sun
If "% PRODUCTION_MODE %" = "true" goto sun_prod_mode
Set JAVA_VM =-client
Set MEM_ARGS =-Xms256m-Xmx512m-XX: MaxPermSize = 256 m
Set JAVA_OPTIONS = % JAVA_OPTIONS %-Xverify: none
Goto continue
: Sun_prod_mode
Set JAVA_VM =-server
Set MEM_ARGS =-Xms256m-Xmx512m-XX: MaxPermSize = 256 m
Goto continue

 

 

 

 

 

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

When running Jboss in Eclipse, sometimes java. lang. OutOfMemoryError: PermGen space may occur after a long time. Here we will introduce a solution:

1) Click the Small Arrow next to the debug icon;

2) Click "Debug deployments ..." 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 = 64 m-XX: MaxPermSize = 256 m

5) if you use the command line mode or directly click "run. bat "to run JBoss, then you need to run in bin/run. modify the JVM option in the conf file and find JAVA_OPTS = "-Xms128m-Xmx512m ..." This section is followed by "-XX: PermSize = 64 m-XX: MaxPermSize = 256m ". Save and OK.

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

 

 

Exception Handling for java. lang. OutOfMemoryError in Resin

Cause:
This error occurs because the JVM physical memory is too small. By default, the maximum memory size of the Java Virtual Machine is only 64 MB, which may be no problem during development and debugging, but it is far from sufficient in the actual application environment unless your application is very small, no traffic. Otherwise, you may find the java. lang. OutOfMemoryError package after the program runs for a period of time. Therefore, we need to increase the memory size of the resin available virtual machine.

Solution:
Modify the args option in/usr/local/resin/bin/httpd. sh.
Add parameters-Xms (initial memory) and-Xmx (maximum memory size available)
It can be used to limit the JVM's physical memory usage.
For example:
Args = "-Xms128m-Xmx256m"
After setting, the initial physical memory of JVM is 128 MB, and the maximum physical memory available is 256 MB.
These two values should be set by the system administrator based on the actual situation of the server.

This article is from "a453228609"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.