Tomcat memory overflow solution in Linux

Source: Internet
Author: User

View logs with the command tail-f/root/apache-tomcat-6.0.20/logs/catalina.out (need to find the Tomcat path) to see if there are any errors

The Tomcat memory overflow workaround in Linux
is commonly found in the following three scenarios:
1.outofmemoryerror:java heap Space
2.outofmemoryerror:permgen Space
3.outofmemoryerror:unable to create new native thread.
The first two usually work together, that is, by using the following
Linux under the catalina.sh file, add the following statement, the file is in the Tomcat-->bin directory.
java_opts= '-xms1024m-xmx1024m-xx:permsize=256m-xx:maxnewsize=512m-xx:maxpermsize=512m '
The third type cannot create a new thread.
This is a rare and strange phenomenon, mainly related to the ratio of JVM to system memory. The strange thing about the
is that the JVM has been allocated a lot of memory (such as 1.5G) by the system, and it consumes at least half of the available memory. It has been found that the more memory you allocate to the JVM, the greater the likelihood that the above error will occur, given the large number of threads.
Each 32-bit process can use up to 2G of available memory, because another 2G is reserved by the operating system. This assumes that 1.5G is used for the JVM, and then the remaining 500M of available memory. This 500M part of the memory must be used to load the system DLL, then the real left is perhaps only 400M, and now the key point arises: When you use Java to create a thread, in the JVM's memory will also create a thread object, But it also creates a real physical thread in the operating system (referencing the JVM specification), and the operating system creates the physical thread in the remaining 400 megabytes of memory, rather than in the 1500M memory heap of the JVM. In jdk1.4, the default stack size is 256KB, but in jdk1.5, the default stack size is 1M per thread, so we can create up to 400 available threads in the remaining 400M of available memory.
The conclusion is that to create more threads, you must reduce the maximum memory allocated to the JVM. Another option is to have the JVM host inside your JNI code.

Give an estimate formula for the maximum number of threads that can be created:
(maxprocessmemory-jvmmemory-reservedosmemory)/
(threadstacksize) = number of threads
For jdk1.5, assume that the operating system retains 120M of memory:
1.5GB JVM: (2GB-1.5GB-120MB)/(1MB) = ~380 threads
1.0GB JVM: (2GB-1.0GB-120MB)/(1MB) = ~880 threads
In 2000/xp/2003 's boot. INI, there is a boot option, as if:/pae/3g, which allows the user process to expand the maximum memory to 3G, when the operating system can only occupy up to 1G of virtual storage. That should allow the JVM to create more threads.
These are some of the solutions for Tomcat memory overflow.

Tomcat memory overflow solution in Linux

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.