Java. Lang. outofmemoryerror

Source: Internet
Author: User
Tags xms

From: http://hi.baidu.com/cjxgotofly/blog/item/ef981434e2e112355ab5f55f.html

 

Java. Lang. outofmemoryerrorTroubleshooting

 

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.CodeThere are endless loops or loops 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.ProgramAn endless loop occurs.
4. When an outofmemoryerror occurs during Tomcat deployment and running, increase the memory parameter value to solve this problem.

 

 

 

 

TomcatJava. Lang. outofmemoryerror: Java heap SpaceException Handling

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"

 

 

TomcatJava. Lang. outofmemoryerror: permgen SpaceException Handling

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.

 

 

WebLogicJava. Lang. outofmemoryerrorException Handling

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

 

 

 

 

 

EclipseRun JBossJava. Lang. outofmemoryerror: Permgen SpaceException Handling

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.

 

 

ResinJava. Lang. outofmemoryerrorException Handling

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.

 

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.