Java.lang.OutOfMemoryError Exception Resolution method

Source: Internet
Author: User

Reprint: http://blog.csdn.net/lxlterry/article/details/9162169

Reason:
The following are common:
1. The amount of data loaded in memory is too large, such as fetching too much data from the database at once;
2. There are references to objects in the collection class that are not emptied after use, so that the JVM cannot be recycled;
3. There are dead loops or loops in the code that produce too many duplicate object entities;
4. Bugs in the use of third-party software;
5. Startup parameter memory value setting is too small;

Common Error Hints:
1.tomcat:java.lang.outofmemoryerror:permgen Space
2.tomcat:java.lang.outofmemoryerror:java Heap Space
3.tomcat:java.lang.outofmemoryerror:unable to create new native thread
4.weblogic:root cause of Servletexception java.lang.OutOfMemoryError
5.resin:java.lang.outofmemoryerror
6.java:java.lang.outofmemoryerror

There are two types of situations:
1. Start Tomcat with a DOS window
Under Windows, in file {Tomcat_home}/bin/catalina.bat
The following settings can be added at the beginning of the file:
Set java_opts=-xms512m-xmx512m-xss1024k-xx:maxnewsize=256m-xx:maxpermsize=256m
Unix/linux, in front of the file {tomcat_home}/bin/catalina.sh, you can add the following settings:
java_opts= '-xms512m-xmx512m-xss1024k-xx:maxnewsize=256m-xx:maxpermsize=256m '
Explanation of each parameter:
-XMS: The size of the memory stack when the program is initialized.
-XMX: The maximum amount of memory that the application (not the JVM) can use, and this value should not be set too large, exceeding the machine memory. Otherwise, Tomcat will not start. This value can be set to the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes.
-XSS: Sets the stack size for each thread. After JDK5.0, each thread has a stack size of 1M.
-xx:maxpermsize: Setting the persistent generation size
-xx:newsize: Setting the young generation size

2. Tomcat as a system service
Modify the Service.bat file under the Bin folder under the Tomcat path
Find "%executable%"//us//%service_name%--jvmoptions
Add in the middle of the following double quotation mark "":-xms512m;-xmx1024m;-xx:newratio=3;-xx:permsize=256m;-xx:maxpermsize=512m;-xx:-usegcoverheadlimit ;
Then uninstall the service, reinstall it again, start it, take effect.

-----------------------------------------------------
1. Java.lang.OutOfMemoryError:unable to create new native thread
A common occurrence in the
Set java_opts=-xms512m-xmx512m-xss1024k-xx:maxnewsize=256m-xx:maxpermsize=256m
After setting
The heap requested by the JVM will occupy the same size address space. In a Windows 32-bit operating system, the address space assigned to each program is only 2GB (and of course 3GB switches).
This is why the heap of each different JVM and the process stack it creates depend on the same process address space.
There are ways to increase the number of threads created: Reduce the size of a single line stacks, and use the-XSS parameter in JVM startup.
Suggestions
Set java_opts=-xms512m-xmx512m-xss512k-xx:maxnewsize=256m-xx:maxpermsize=256m

2, Exception in thread "main" Java.lang.OutOfMemoryError:GC overhead limit exceeded
A common occurrence in the
Add in the middle of the following double quotation mark "":-xms512m;-xmx1024m;-xx:newratio=3;-xx:permsize=256m;-xx:maxpermsize=512m;-xx:-usegcoverheadlimit ;
After setting
JDK6 new error type. Thrown when a GC takes up a lot of time to free up a small space.
Generally because the heap is too small. Cause of the exception: there is not enough memory.
Suggestions
Add a-xx:-usegcoverheadlimit in the middle of the double quotation mark "";

Java.lang.OutOfMemoryError Exception Resolution method

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.