tomcat memory overflow setting JAVA_OPTS
Answer 1
Set the initial memory for Tomcat startup
Its initial space (i.e. -Xms) is 1/64 of physical memory, and the maximum space (-Xmx) is 1/4 of physical memory. You can use the -Xmn -Xms -Xmx and other options provided by the JVM
Make settings
3. Examples, the following gives the reference for setting parameters of java jvm in 1G memory environment:
JAVA_OPTS="-server -Xms800m -Xmx800m
-XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true "
JAVA_OPTS="-server -Xms768m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:
NewSize=192m -XX:MaxNewSize=384m"
CATALINA_OPTS="-server -Xms768m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=256m
-XX:NewSize=192m -XX:MaxNewSize=384m"
Linux:
catalina.sh in the /usr/local/apache-tomcat-5.5.23/bin directory
Added: JAVA_OPTS='-Xms512m -Xmx1024m'
If you want to add "m", it means that it is MB, otherwise it will be KB, and there will be insufficient memory when starting tomcat.
-Xms: Initial value
-Xmx: Maximum value
-Xmn: Minimum value
Windows
Join in front of catalina.bat
set JAVA_OPTS=-Xms128m -Xmx350m
If you start tomcat with startup.bat, the OK setting will take effect. 200M memory will be allocated successfully.
However, if you do not execute startup.bat to start tomcat but use Windows system service to start tomcat service, the above settings will not take effect.
That is to say, set JAVA_OPTS=-Xms128m -Xmx350m does not work. If you allocate 200M of memory above, you will be OOM...
The windows service executes bin/tomcat.exe. It reads the value in the registry, not the catalina.bat setting.
Solution:
Modify the registry HKEY_LOCAL_MACHINE/SOFTWARE/Apache Software Foundation/Tomcat Service Manager/Tomcat5/Parameters/JavaOptions
The original value is
-Dcatalina.home="C:/ApacheGroup/Tomcat 5.0"
-Djava.endorsed.dirs="C:/ApacheGroup/Tomcat 5.0/common/endorsed"
-Xrs
Add -Xms300m -Xmx350m
Restart the tomcat service, and the settings take effect
Answer 2
Tomcat's JVM memory overflow problem solution
Keyword: Tomcat's jvm memory overflow problem solution
Recently, I am familiar with a project that has been developed for several years. I need to port the database from mysql to oracle. First, point the jdbc connection to mysql, package it into tomcat, and run it. There is no problem. However, when pointing the jdbc connection to oracle, tomcat continuously throws the java.lang.OutOfMemoryError error, google the Internet, understand the operating mechanism of tomcat, and solve the problem. Share it for reference.
1. First is: java.lang.OutOfMemoryError: Java heap space
explain:
Heap size settings
The settings of the JVM heap refer to the settings of the memory space that the JVM can provision during the Java program run. When the JVM starts up, it will automatically set the value of Heap size. Its initial space (i.e. -Xms) is 1/64 of physical memory, and the maximum space (-Xmx) is 1/4 of physical memory. You can use the -Xmn -Xms -Xmx and other options provided by the JVM to set it. The size of Heap size is the sum of Young Generation and Tenured Generaion.
Tip: This exception message will be thrown if 98% of the time is used for GC and the available Heap size is less than 2%.
Tip: The maximum Heap Size should not exceed 80% of the available physical memory. Generally, set the -Xms and -Xmx options to the same, while -Xmn is 1/4 of the -Xmx value.
Solution:
Set Heap size manually
Modify TOMCAT_HOME/bin/catalina.bat and add the following line to "echo "Using CATALINA_BASE: $CATALINA_BASE":
Java code
set JAVA_OPTS=%JAVA_OPTS% -server -Xms800m -Xmx800m -XX:MaxNewSize=256m
set JAVA_OPTS=%JAVA_OPTS% -server -Xms800m -Xmx800m -XX:MaxNewSize=256m
Or modify catalina.sh
Add the following line to "echo "Using CATALINA_BASE: $CATALINA_BASE":
JAVA_OPTS="$JAVA_OPTS -server -Xms800m -Xmx800m -XX:MaxNewSize=256m"
2. Secondly: java.lang.OutOfMemoryError: PermGen space
reason:
The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of memory. This memory is mainly stored by the JVM in Class and Meta information. Class will be placed in PermGen space when it is loaded. It is different from the Heap area where the class instance (Instance) is stored. GC (Garbage Collection) will not clean up PermGen space during the main program runtime. Therefore, if there is a lot of CLASS in your application, it is very likely that PermGen space error will occur. This error is common when the web server precompiles JSP. If you use a large number of third-party jars under your WEB APP, the size exceeds the default size of jvm (4M), then this error message will be generated.
Solution:
1. Manually set the MaxPermSize size
Modify TOMCAT_HOME/bin/catalina.bat (catalina.sh under Linux), in Java code
"echo "Using CATALINA_BASE: $CATALINA_BASE"" adds the following line:
set JAVA_OPTS=%JAVA_OPTS% -server -XX:PermSize=128M -XX:MaxPermSize=512m
"echo "Using CATALINA_BASE: $CATALINA_BASE"" adds the following line:
set JAVA_OPTS=%JAVA_OPTS% -server -XX:PermSize=128M -XX:MaxPermSize=512m
catalina.sh is:
Java code
JAVA_OPTS="$JAVA_OPTS -server -XX:PermSize=128M -XX:MaxPermSize=512m"
JAVA_OPTS="$JAVA_OPTS -server -XX:PermSize=128M -XX:MaxPermSize=512m"
I also saw another post and thought it was very good. The excerpts are as follows:
Analysis java.lang.OutOfMemoryError: PermGen space
I found that many people attribute the problem to: spring, hibernate, tomcat, because they generate classes dynamically, causing permanent heap in the JVM to overflow. Then there are many different opinions on the solution. Some people say that upgrading tomcat version to the latest is not even necessary tomcat. Some people also doubt the problem of spring, and it is very hot in the spring forum, because using CBLIB in spring when AOP will dynamically generate many classes.
But the question is why the same problem occurs with these trump card open source, so is it a more basic reason? Tomcat answered this in a very obscure way in Q&A. We know this question, but this question arises from a more basic question.
So someone checked the more basic JVM and found the key to the problem. It turns out that SUN's JVM divides memory into different areas, one of which is the permenter area to store a lot of classes and class descriptions. Originally, when SUN was designed, it was believed that this area was fixed when the JVM was started, but he did not expect that the dynamics would be so widely used now. Moreover, this area has a special garbage collection mechanism. The current problem is that after dynamically loading the class into this area, gc cannot recycle it!
For the above two questions, my handling is:
Add in the first line of catalina.bat:
Java code
set JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m
set JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m
Add in the first line of catalina.sh:
Java code
JAVA_OPTS=
-Xms64m
-Xmx256m
-XX:PermSize=128M
-XX:MaxNewSize=256m
-XX:MaxPermSize=256m
The perfect solution to tomcat memory overflow in the above article is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.