Solve the tomcat memory overflow problem-Linux Enterprise Application-Linux server application information. The following is a detailed description. Tomcat is a Java servlet container and web server widely used at present. I have been using 5.5.9 since 4.0.6 for five years. During this period, I also encountered several crashes and threw logs similar to hs_err_pid31199.log, however, most of the time is stable. But java. lang. the exception of OutOfMemoryError is believed to have been encountered by all people who have actually used tomcat. Aside from program issues (Borland's optimizeit can be used for searching, and the code may have obj that should have existed for a short time, but it is referenced by a long life-cycle ref, so gc cannot recycle this obj. Mostly related to static objects). This exception is related to the default JVM memory limit of MB. If your business is busy enough, Mb is far from enough, fortunately, the current memory has almost reached the cabbage price (about 1 GB today is 260 yuan), and the average server has 2-4 GB memory, therefore, you can allocate 1 GB or more memory to the JVM to avoid memory overflow or greatly increase the exception period.
1. linux is simple. find catalina. sh and vi in the bin, and add a sentence following the comment:
JAVA_OPTS = '-Xms256m-xmx256m'
256 is an example. You can write it as 1024 or even 2048 based on the physical memory, but I personally suggest that 1024 is enough.
: After wq, restart tomcat. After ps ax, the tomcat process will become similar.
2. In windows, if you use the console, that is, you can directly execute startup. bat to start the program, you can modify catalina. bat.
Set JAVA_OPTS =-Xms256m-Xmx512m
Note: There are single quotation marks in linux and won't be used in win. If single quotation marks are added, tomcat cannot start.
3. If tomcat is installed as a service in windows, modifying the available memory of jvm may be troublesome, but this can be solved perfectly.
At? Tomcat? R? "NT Service (NT/2000/XP only )"
? T? After the task is completed? Object? "Bin" Object ???? Lucky ?? Tomcat.exe? N case
Take tomcat server first? 5? Br/> in command column mode (run CMD)
? ? Cut? Q to the bin of tomcat?
Run the following command to get the server? Why? Br/> tomcat-uninstall "Apache Tomcat 4.1"
Next? Why? Hammer ?? Why? Br/>
? Hot failover? Br/> set SERVICENAME = Apache Tomcat 4.1
Set CATALINA_HOME = E: \ Tomcat 4.1.24
Set CLASSPATH = D: \ j2sdk1.4.1 _ 01 \ lib
Set JAVACLASSPATH = % CLASSPATH %
Set JAVACLASSPATH = % JAVACLASSPATH %; % CATALINA_HOME % \ bin \ bootstrap. jar
Set JAVACLASSPATH = % JAVACLASSPATH %; % CATALINA_HOME % \ common \ lib \ servlet. jar
Set JAVACLASSPATH = % JAVACLASSPATH %; % JAVA_HOME % \ lib \ tools. jar
Tomcat.exe-install "% SERVICENAME %" "% JAVA_HOME % \ jre \ bin \ server \ jvm. dll "-Djava. class. path = "% JAVACLASSPATH %"-Dcatalina. home = "% CATALINA_HOME %"-Xms512m-Xmx768m-start org. apache. catalina. startup. bootstrap-params start-stop org. apache. catalina. startup. bootstrap-params stop-out "% CATALINA_HOME % \ logs \ stdout. log "-err" % CATALINA_HOME % \ logs \ stderr. log"
The last line starts with atat.exe-install! Do not manually press enter to wrap the line into several segments. Save and execute the bat file in the command line. Note that the "service" window is closed during execution.
If the execution result is the same, congratulations! A tomcat service with large memory is born.
If you encounter "the service cannot be started, an internal problem" when starting a new service on the cloud, it is likely that the JDK has a problem. Once, manually go to "environment variables" (I want to install tomcat, at least it is old bird, you will not find the location of environment variable settings ?) Add JAVA_HOME to the system variables, write the variable value to the actual jDK path, uninstall the tomcat service again, and reinstall the tomcat service. Generally, this is okay.
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