80

Possible Duplicate:
Dealing with “java.lang.OutOfMemoryError: PermGen space” error

I have 8GB RAM in my development machine, and am trying to run Apache Tomcat (7.0.29) to host both Artifactory (2.6.3) and Jenkins (1.479) at the same time. I tried to find the memory requirements for Jenkins but it looks like their wiki is down.

In ${TOMCAT_HOME}/bin/catalina.sh, I have added the following command:

CATALINA_OPTS="$CATALINA_OPTS -server -Xms1024m -Xmx3052m"

This should keep Tomcat's JVM between (essentially) 1 and 3 GB in size, leaving me plenty of room for other stuff, and giving Tomcat enough memory for Artifactory/Jenkins, and even others if I wanted.

(For what it's worth I've tried the same with JAVA_OPTS only to get the same exact result). I save that change and run startup.sh. Tomcat begins to start up, and then dies with OOMEs complaining that Tomcat has ran out of PermGen space:

Exception in thread "SocketListener(<hex-stuff>.local.)"
java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space
Exception in thread "hudson initialization thread" java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space

Where am I going awrye here? I have read multiple articles on how to do this and (believe!) I'm following them precisely. Any thoughts, or ideas as to how I could debug this further? Thanks in advance!

Community
  • 1
  • 1
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756

1 Answers1

144

try setting this

CATALINA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

in {$tomcat-folder}\bin\setenv.sh (create it if necessary).

See http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ for more details.

whlk
  • 15,487
  • 13
  • 66
  • 96
sgpalit
  • 2,676
  • 2
  • 16
  • 22
  • 14
    Hi, please refrain from link-only answers, and try to get as much as possible into the main answer – epoch Oct 02 '12 at 10:44
  • 1
    Thanks @sgpalit (+1) - I'll give it a try here soon. Just curious, if I want my Java heap to be ~3GB in size, how big should my PermGen be? – IAmYourFaja Oct 02 '12 at 10:56
  • The PermGem memory is used to compile and optimize classes. So it dependes on your application how much perm gen you should use. It should be as little as possible (to leave as much for the heap), but not too small that it runs out. – Augusto Oct 02 '12 at 11:19
  • As Augusto mentioned your PermGen size should not too big. Usually I use 256m for artifactory and hudson, it is enough. For detailed information you can look to the below article. http://www.integratingstuff.com/2011/07/24/understanding-and-avoiding-the-java-permgen-space-error/ – sgpalit Oct 02 '12 at 12:28
  • 2
    In my case I didn't modify the sh file. I was a bit discouraged by the fact that on the server there is yum repo and Tomcat was installed from there. I just modified `/usr/share/tomcat7/conf/tomcat7.conf` and added the aforementioned options. – Vic Nov 12 '13 at 11:56
  • 32
    The RUNNING.txt that comes with Tomcat states: "Note: Do not use JAVA_OPTS to specify memory limits. You do not need much memory for a small process that is used to stop Tomcat. Those settings belong to CATALINA_OPTS." As this seems to be a well read answer, you may add that. – bentrm Feb 04 '14 at 09:32
  • 1
    A 1.5 Gig stack is excessive -Xms1536m. A much smaller -Xms128m or -Xms256m should be plenty. This would allow the heap size -Xmx1536m could be increased to say -Xmx2048m – Martin Spamer Feb 12 '14 at 10:27
  • 2
    @MartinSpamer - `-Xms` has nothing to do with stack size. See `java -X` for a description of what these settings *actually* do. Using `-Xms1536m` is perfectly reasonable, and having `-Xms` set to the same as `-Xmx` makes the process more efficient if you know it is eventually going to use all or nearly all of its heap. – Jules Jan 16 '18 at 12:48
  • Also if tomcat is running on windows as a windows service the catalina.bat says this: "The configuration that controls Windows Services is stored in the Windows Registry, and is most conveniently maintained using the "tomcatXw.exe" maintenance utility, where "X" is the major version of Tomcat you are running." – Doc Sep 25 '18 at 20:41