How to make sure that Tomcat6 reads CATALINA_OPTS on Windows?

三世轮回 提交于 2019-12-03 08:45:56

问题


I have a Tomcat6 running on a Windows2003 machine. I deployed 2 Grails apps on this server and I soon noticed that everything was crashing sometime after the deploy with a classic PermGen error.

java.lang.OutOfMemoryError: PermGen space
 java.lang.ClassLoader.defineClass1(Native Method)
 java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
 java.lang.ClassLoader.defineClass(ClassLoader.java:616)
 org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.de 
...

So I found a common fix for this problem: increasing heap and permgen space with:

set CATALINA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m"

Added into C:\apache-tomcat-6.0.26\bin\catalina.bat. Unfortunately this didn't work, but the problem is that I'm not sure that Tomcat is picking it up. I checked various logs but these options are never printed out. Is there a way to log them and make sure that Tomcat has read them?

EDIT: I tried to add the following JVM options with tomcat6w.exe:

-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled 
-XX:+UseConcMarkSweepGC

And nothing changed. I get a permGen after 2-3 minutes of uptime. Any other idea?

Cheers! Mulone


回答1:


Thank you all! I finally solved the issue by adding:

-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled
-XX:+UseConcMarkSweepGC
-XX:PermSize=128m
-XX:MaxPermSize=512m 

To the java options on tomcat6w.exe.

Thanks!




回答2:


Actual way to do it (in Catalina.bat),

set "JAVA_OPTS=-Djava.awt.headless=true -server -Xms512m -Xmx2048m -XX:PermSize=512m -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"

add this line in such a position so that this JAVA_OPTS is transferred to any of _EXECJAVA command at the end of file (if-else nested). I personally write this line as first statement of this batch




回答3:


I actually set those as JAVA_OPTS for my JVM before starting the server

JAVA_OPTS=-Djvmarg='-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m'



回答4:


Look where you are setting it, use echo [statements] to troubleshoot, try setting it right before its passed to the VM, something like:

set CATALINA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m"
_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% 
-Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" 
-Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" 
-Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%

Make sure you have the right EXEC_JAVA not sure which version of the .bat file you have, but probably several if statements.

Also make sure these are valid arguments for your VM.

You can check your max heap size within your java code, use:

long heapMaxSize = Runtime.getRuntime().maxMemory();

Just print it out, if its correct based on your settings, you have a bad memory leak, if its not, then tomcat is not picking it up.



来源:https://stackoverflow.com/questions/3583757/how-to-make-sure-that-tomcat6-reads-catalina-opts-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!