Several scenarios where memory overflow occurs in Java

Source: Internet
Author: User

Situation one: Java.lang.OutOfMemoryError:Java heap space

Cause: The Java heap is running out of memory, may be really inadequate, or it may be a dead loop in the program

Scenario: 1, Tuning JVM parameters-xms2048m-xmx2048m

2. Locating the Dead Loop code

Scenario Two: Java.lang.OutOfMemoryError:GC overhead limit exceeded

Cause: JDK6 adds a new error type that is thrown when the GC is taking a lot of time to free up a small space, usually because the heap is too small to cause an exception, not enough memory

Scenario: 1. Check the system for any code that uses large memory or a dead loop

2, add the JVM parameter configuration, to limit the use of memory:-xx:-usegcoverheadlimit

Scenario Three: Java.lang.OutOfMemoryError:PermGen space

Cause: Insufficient memory in the Perm area

Scenario:-xx:maxpermsize=128m-xx:permsize=128m

Situation four: Java.lang.OutOfMemoryError:Direct buffer memory

Reason: Adjust the-xx:maxdirectmemorysize= parameter

Scenario:-xx:maxdirectmemorysize=128m

Scenario Five: Java.lang.OutOfMemoryError:unable to create new native thread

Cause: Stack space is not enough to create additional threads, either too many threads are created, or the stack space is really small

Scenario: Because the JVM does not provide parameters to set the total stack space size, but can set the size of a single line stacks, and the system's user space is a total of 3G, in addition to text/data/bss/memorymapping a few paragraphs, heap and stack space is limited, It is the one that has been eliminated. Therefore, there are two ways to solve this error: 1. Reduce the size of a single thread stack by-XSS startup parameters, so that more threads can be opened (not too small, too small to appear stackoverflowerror), 2. Reduce the heap size by-xms-xmx two parameters, Give the memory to the stack (provided that the heap space is sufficient)

Situation VI: Java.lang.StackOverflowError

Cause: This is also a memory overflow error, that is, the overflow of the line stacks, either the method call hierarchy too many (such as there is an infinite recursive call), or the line stacks is too small

Program: Optimize the program design, reduce the method call level; Adjust the-XSS parameter to increase the thread stack size

Several scenarios where memory overflow occurs in Java

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.