How to modify and monitor the number of JVM memory occupied by Tomcat

Source: Internet
Author: User
Tomcat itself is a good server container. It is free of charge and powerful. It is quietly supported by many powerful companies and organizations behind it, creating a position that can compete with Weblogic and other charged containers, however, Tomcat still has some defects.
At the beginning of Tomcat's design, considering the performance of the customer's servers and preventing virtual memory insufficiency, Tomcat sets the JVM to allow a minimum of 64 M memory and a maximum of 128 m by default, however, in projects that occupy a large amount of resources or have a high concurrency, it is easy to cause insufficient memory and tomcat stops automatically without any indication.
The best way is to modify Tomcat's restrictions on JVM memory usage.
There are two methods:
1. Edit the Catalina. BAT file under % catalina_home %/bin and write it at the beginning of the line.
Set java_opts =-xms512m-xmx1024m
-XMS indicates the minimum JVM memory and-xmx indicates the maximum memory.
For example, here I set it to a minimum of 512 and a maximum of 1024.
Of course, the minimum and maximum values are not limited to 1024. In fact, this setting is for the system, because the JVM memory usage is actually for the virtual memory, no matter how the system occupies the virtual memory, we must ensure that the virtual memory with a minimum of 1024 MB is used by JVM. Of course, even if I occupy a larger JVM, it will not exceed, which threatens the system's memory usage.
2. Add the following two values to the environment variable:
Add the tomcat_opts and catalina_opts attributes,
For example, set catalina_opts =-xms512m-xmx1024m;
Meaning same as above

But how can I check the JVM memory usage? The simplest way is to open the Task Manager-> process-> View-> select a column, select the number of virtual memory-> confirm, and you will see the number of virtual memory, you will see that the virtual memory will be 512 ~ The space occupied by MB is occupied by the preset value. The JVM memory usage will be used within the occupied range.

Another way is to write a small script named Ram. jsp.
The code is

<%
Runtime lruntime = runtime. getruntime ();
Out. println ("*** begin memery statistics *** </BR> ");
Out. println ("free momery:" + lruntime. freememory () + "</BR> ");
Out. println ("Max momery:" + lruntime. maxmemory () + "</BR> ");
Out. println ("total momery:" + lruntime. totalmemory () + "</BR> ");
Out. println ("available processors:" + lruntime. availableprocessors () + "</BR> ");
Out. println ("*** end memery statistics ***");
%>

What does it mean? I believe you will understand it after running it :)

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.