How to clear PermGen space Error in tomcat
Asked Answered
S

11

54

I am working in a Windows Environment, and I am getting this error every time I am working with tomcat-

Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@4ae53a99
2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connection refused: no further information
Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
Exception in thread "Memcached IO over {MemcachedConnection to localhost/127.0.0.1:11211}" java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process
SEVERE: Error processing request
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process
SEVERE: Error processing request
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process
SEVERE: Error processing request
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:41 PM org.apache.catalina.connector.CoyoteAdapter service
SEVERE: An exception or error occurred in the container during the request processing
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:43 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.action]
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:42 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.action]
java.lang.OutOfMemoryError: PermGen space
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space

I tried adding JAVA_OPTS with the value as -Xms1024m -Xmx1024m in System Variables, but I am stillgetting the same error (java.lang.OutOfMemoryError: PermGen space) again and again.

Any help will be appreciated. I have also read other posts on Stack Overflow also but it didn't work out.

Schoenfeld answered 1/5, 2012 at 0:43 Comment(1)
if you are using "-Xnoclassgc" remove it and tryAppulse
L
107

The PermGen space is what Tomcat uses to store class definitions (definitions only, no instantiations) and string pools that have been interned. From experience, the PermGen space issues tend to happen frequently in dev environments really since Tomcat has to load new classes every time it deploys a WAR or does a jspc (when you edit a jsp file). Personally, I tend to deploy and redeploy wars a lot when I’m in dev testing so I know I’m bound to run out sooner or later (primarily because Java’s GC cycles are still kinda crap so if you redeploy your wars quickly and frequently enough, the space fills up faster than they can manage).

This should theoretically be less of an issue in production environments since you (hopefully) don’t change the codebase on a 10 minute basis. If it still occurs, that just means your codebase (and corresponding library dependencies) are too large for the default memory allocation and you’ll just need to mess around with stack and heap allocation. I think the standards are stuff like:

-XX:MaxPermSize=SIZE

I’ve found however the best way to take care of that for good is to allow classes to be unloaded so your PermGen never runs out:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

Stuff like that worked magic for me in the past. One thing tho, there’s a significant performance tradeoff in using those, since permgen sweeps will make like an extra 2 requests for every request you make or something along those lines. You’ll need to balance your use with the tradeoffs.

Locarno answered 1/5, 2012 at 1:6 Comment(5)
Thanks for the comment, so according to you I should add these things as value for JAVA_OPTS -XX:MaxPermSize=128M -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabledSchoenfeld
@Schoenfeld had this solved your problem? and where exactly did you put these lines, in setenv.sh?Daryldaryle
For CMSPermGenSweepingEnabled to have any impact, UseConcMarkSweepGC must be set. #3335411Couture
where i add thisIncantatory
Where to add this values i added in CATALINA_OPTS=-Djava.awt.headless=true -Xms2048m -Xmx4096m -XX:PermSize=1024m -XX:MaxPermSize=2048m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled and added in environment in eclipse tomcat profile but error is still thereQuinquevalent
M
17

You have to allocate more space to the PermGenSpace of the tomcat JVM.

This can be done with the JVM argument : -XX:MaxPermSize=128m

By default, the PermGen space is 64M (and it contains all compiled classes, so if you have a lot of jar (classes) in your classpath, you may indeed fill this space).

On a side note, you can monitor the size of the PermGen space with JVisualVM and you can even inspect its content with YourKit Java Profiler

Mithras answered 1/5, 2012 at 0:57 Comment(1)
Thanks for the comment, so according to you I should add these things as value for JAVA_OPTS -XX:MaxPermSize=128M -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabledSchoenfeld
T
10

To complement Michael's answer, and according to this answer, a safe way to deal with the problem is to use the following arguments:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+UseConcMarkSweepGC
Trump answered 29/10, 2013 at 10:10 Comment(1)
Tomcat 7.0.47 displays a warning which states to replace 'CMSPermGenSweepingEnabled' with 'CMSClassUnloadingEnabled'Invar
A
5

If tomcat is running as Windows Service neither CATALINA_OPTS nor JAVA_OPTS seems to have any effect.

You need to set it in Java options in GUI.

The below link explains it well

http://www.12robots.com/index.cfm/2010/10/8/Giving-more-memory-to-the-Tomcat-Service-in-Windows

Automatize answered 26/9, 2014 at 8:19 Comment(0)
G
3

In Tomcat 7.0 Windows Service Installer Version.There is not catalina.bat in /bin . So you need open Tomcat7w.exe in /bin and add blow JVM argument

-XX:PermSize=256m -XX:MaxPermSize=512m

on Java Option in Java Tab, like this. You also add other options.

enter image description here

Another, if you use IntellijIDEA you need add JVM argument in Server Configurations,like this.

enter image description here

Guinea answered 18/12, 2015 at 7:44 Comment(0)
F
2

This one worked for me, in startup.bat the following line needs to be added if it doesn't exist set JAVA_OPTS with the value -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256. The full line:

set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256
Fotinas answered 29/6, 2015 at 14:2 Comment(0)
L
2

@AndreSmiley 's code of line worked for me.

only modification required is.

-XX:MaxPermSize=256m

"m" means MB.

Actually my application is kinda huge so i was advised to make it 1024m for performance.

Loosen answered 15/10, 2015 at 22:51 Comment(0)
C
1

If your using eclipse with tomcat follow the below steps

  1. On server window Double click on tomcat, It will open the tomcat's Overview window .

  2. In the Overview window you will find Open launch configuration under General information and click on Open launch configuration.

  3. In the edit Configuration window look for Arguments and click on It.
  4. In the arguments tag look for VM arguments.
  5. simply paste this -Xms256m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=512m to the end of the arguments.

edit launch configuration properties

Cabriolet answered 4/2, 2016 at 6:29 Comment(0)
T
1

I'm running tomcat7 on CentOS 6.6. I tried creating a new /usr/share/tomcat/bin/setenv.sh file and setting both JAVA_OPTS and CATALINA_OPTS. But tomcat wouldn't pick up the values on restart. When I put the following line into /etc/tomcat/tomcat.conf:

CATALINA_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=1024m"

tomcat did pick up the new environment variable. I verified this by running

ps aux | grep tomcat

and seeing the new settings in the output. This took a long time to diagnose and I didn't see anyone else suggesting this, so I thought I'd throw it out to the internet community.

Transpierce answered 5/2, 2016 at 9:31 Comment(0)
B
0

I tried the same on Intellij Ideav11.

It was not picking up the settings after checking the process using grep. In case it does not, give the mem settings for JAVA_OPTS in catalina.sh instead.

Burgos answered 8/3, 2018 at 19:52 Comment(0)
A
-5

Killing the tomcat process(forcefully, kill -9 for Linux) and starting it again solves the issue. My guess is, the tomcat instance doesn't get killed properly using shutdown.bat. So, we need to forcefully kill the process and start again.

Ague answered 2/5, 2014 at 19:26 Comment(1)
Killing the process doesn't fix the issue the next time he wants to use it.Seifert

© 2022 - 2024 — McMap. All rights reserved.