Summary of Tomcat running Java Web memory overflow

Source: Internet
Author: User

If the program running in JVM is full of its memory heap and persistent storage region, and the program wants to create an object instance, the garbage collector will start, try to release enough memory to create this object. At this time, if the garbage collector is unable to release enough memory, it will throw an OutOfMemoryError memory overflow error.

Sun jvm memory management method:

SUN's JVM is similar to the human family, that is, creating objects in a place, giving it multiple chances of death before it occupies space for a long time. sun jvm is divided:

1. Young generation (Young generation), including EDEN and two survivor spaces (From space and To space)

2. Old generation (Old generation)

3. Permanent generation (Permanent generation)

Generally, the data partitions of Java virtual machines are not necessarily physical partitions ):

1. Heap: Mainly stores object instances and threads share

2. STACK: stores the method call status of a specific thread, exclusively occupied by the thread

3. Local method Stack: stores the call status of local methods and exclusively occupies threads.

4. PC register: Anyone who has learned the operating system course knows that the thread is exclusive.

5. Method Area: Mainly stores type information and thread sharing

Therefore, when a memory overflow error is thrown, a message indicating the type of Memory leakage is displayed, which is generally divided by region:

1. heap) Memory leakage java. lang. OutOfMemoryError: Javaheap space: everyone is familiar with it. You can solve this problem by setting-Xms2048m-Xmx4096m.

2. stack) Memory leakage: there are too many intermediate variables maintained during the running of the current thread. For example, a common endless loop causes stack over flow.

3. method Area permanent heap) Memory leakage, that is, java. lang. outOfMemoryError: PermGen space: the cause of the error is directly related to the type loading and unloading. You can solve this problem by setting-XX: MaxNewSize = 256 m-XX: MaxPermSize = m.

Generally, when the server memory is too small and a large number of access services are provided, too many data objects may be cached, resulting in heap memory overflow. When the web application continues to expand, when the size of the loaded lib Library reaches 4 MB, it is easy to report PermGen OOM, that is, the method zone overflow.

Write the parameters to the environment variables on the Linux Server:

 
 
  1. export CATALINA_OPTS="-Xms2048m -Xmx4096m" 
  2. export JAVA_OPTS="-XX:MaxNewSize=256m -XX:MaxPermSize=256m" 

Xmx cannot exceed 80% of the server's physical memory

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.