tomcat set java virtual machine memory

Please reprint from the source: http://eksliang.iteye.com/blog/2117772

http://eksliang.iteye.com/

There are two common memory overflows:

java.lang.OutOfMemoryError: PermGen space

java.lang.OutOfMemoryError: Java heap space

 

---------------------------------------------------------

Taking the tomcat environment as an example, other WEB servers such as jboss, weblogic, etc. are the same.


一、java.lang.OutOfMemoryError: PermGen space

The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​memory.
This memory is mainly used by JVM to store Class and Meta information. When Class is loaded by Loader, it will be placed in PermGen space
. The Heap area of ​​(Instance) is different, and GC (Garbage Collection) will not
clean up the PermGen space during the main program runtime, so if your application has a lot of CLASS, it is likely to have a PermGen space error,
which is common in When the web server precompiles the JSP. If your WEB APP uses a large number of third-party jars, the size of which
exceeds the default size of jvm (4M), then this error message will be generated.
Solution: Manually set the MaxPermSize size
Recommendation: Move the same third-party jar file to the tomcat/shared/lib directory, so as to reduce the memory occupied by the jar file repeatedly.

 

2. java.lang.OutOfMemoryError: Java heap space
The setting of the JVM heap refers to the setting of the memory space that the JVM can allocate and use during the running of the java program. The JVM will automatically set the value of the Heap size when it is started, and
its initial space (ie -Xms) is 1/64 of physical memory , and the maximum space (-Xmx) is 1/4 of physical memory . It can be set by using options such as -Xmn -Xms -Xmx provided by the JVM
. The size of Heap size is the sum of Young Generation and Tenured Generation.
Hint: This exception will be thrown if 98% of the time in the JVM 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, the -Xms and -Xmx options should be set to the same, and -Xmn is 1/4 of the -Xmx value.
Workaround: Manually set the Heap size

----------------------------------------------------------

 

Modify the JVM memory size under Linux:

To be added in catalina.sh under the bin of tomcat , before the location cygwin=false. Note that the quotation marks should be put on, and the red ones are newly added.

# OS specific support.  $var _must_ be set to either true or false.
JAVA_OPTS="-Xms256m -Xmx512m -Xss1024K -XX:PermSize=128m -XX:MaxPermSize=256m"
cygwin=false

 

windows下修改JVM内存大小:

情况一:解压版本的Tomcat, 要通过startup.bat启动tomcat才能加载配置

要添加在tomcat 的bin 下catalina.bat 里

rem Guess CATALINA_HOME if not defined
set CURRENT_DIR=%cd%后面添加,红色的为新添加的.

set JAVA_OPTS=-Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -Djava.awt.headless=true

 

情况二:安装版的Tomcat下没有catalina.bat

windows服务执行的是bin\tomcat.exe.他读取注册表中的值,而不是catalina.bat的设置.

修改注册表HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Tomcat Service Manager\Tomcat5\Parameters\JavaOptions
原值为
-Dcatalina.home="C:\ApacheGroup\Tomcat 5.0"
-Djava.endorsed.dirs="C:\ApacheGroup\Tomcat 5.0\common\endorsed"
-Xrs

加入 -Xms300m -Xmx350m 
重起 tomcat服务,设置生效

 

---------------------------------------------------------

各参数的比例:

Xmx 与PermSize的和不可超过JVM可获得的总内存

PermSize不可大于Xmx 

 

内存详解博客:http://blog.csdn.net/ye1992/article/details/9344807

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326461871&siteId=291194637