OutOfMemoryError: Permgen space - How to set or change permgen size in tomcat server, eclipse?




Contents of page :
  • 1) When to change permgen size in tomcat server?
  • 2) How to set or change permgen size in tomcat server?
  • 3) Where is exactly catalina.bat file located?
  • 4) How to set permgen size in tomcat server in windows, linux and Mac platform >
    • 4.1) How to set permgen size in tomcat server in windows platform >
    • 4.2) How to set permgen size in tomcat server in Linux platform >
    • 4.3) How to set permgen size in tomcat server in Mac OS platform >
  • 5) You may use following VM (JVM) PARAMETERS to set up permgen memory (or permanent generation or permanent space) >
  • 6) You must also know how to change the heap size JVM parameters >
  • 7) How to set or change permgen size in eclipse?


1) When to change permgen size in tomcat server?
Generally when we are facing java.lang.OutOfMemoryError - Java permgen space, then we need to change permgen size of tomcat.

2) How to set or change permgen size in tomcat server?
For setting permgen size in tomcat server you need to make changes values in the Tomcat Catalina start file. Change CATALINA_OPTS option in the file.

3) Where is exactly catalina.bat file located?
tomcatServerHome\bin\catalina.bat


4) How to set permgen size in tomcat server in windows, linux and Mac platform >


4.1) How to set permgen size in tomcat server in windows platform >
Open or create setenv.bat file (Location of setenv.bat file is tomcatHome\bin\setenv.bat)


set CATALINA_OPTS=-server -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m


Best practices while setting permgen size in tomcat server in windows platform >
You should not modify tomcatServerHome\bin\catalina.bat. You should create a new file in tomcatServerHome\bin\setenv.bat to keep your custom environment configurations separate from default tomcat server configurations.



4.2) How to set permgen size in tomcat server in Linux platform >
Open or create setenv.sh file (Location of setenv.bat file is tomcatHome\bin\setenv.sh)


export CATALINA_OPTS="$CATALINA_OPTS=-server -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m

Best practices while setting permgen size in tomcat server in linux platform >
You should not modify tomcatServerHome\bin\catalina.sh. You should create a new file in tomcatServerHome\bin\setenv.sh to keep your custom environment configuartions seperate from defult tomcat server configurations.

4.3) How to set permgen size in tomcat server in Mac OS platform >
Open or create setenv.sh file (Location of setenv.bat file is tomcatHome\bin\setenv.sh)


export CATALINA_OPTS="$CATALINA_OPTS=-server -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m"

Best practices while setting permgen size in tomcat server in Mac OS platform >
You should not modify tomcatServerHome\bin\catalina.sh. You should create a new file in tomcatServerHome\bin\setenv.sh to keep your custom environment configuartions seperate from defult tomcat server configurations.

5) You may use following VM (JVM) PARAMETERS to set up permgen memory (or permanent generation or permanent space) >
Learn how to pass vmargs (VM parameters) to java program in eclipse?

-XX:PermSize: It’s is initial value of Permanent Space which is allocated at startup of JVM.


Example1 of using -XX:PermSize VM (JVM) option in cmd in java >
java -XX:PermSize=512m MyJavaProgram
It will set initial value of Permanent Space as 512 megabytes to JVM


Example2 of using -XX:PermSize VM (JVM) option in java >
java -XX:PermSize=1g MyJavaProgram
It will set initial value of Permanent Space as 512 gigabyte to JVM


-XX:MaxPermSize: It’s maximum value of Permanent Space that JVM can allot up to.


Examples of using -XX:MaxPermSize VM option in java >


Example1 of using -XX:MaxPermSize VM (JVM) option in cmd in java >
java -XX:MaxPermSize=512m MyJavaProgram
It will set maximum value of Permanent Space as 512 megabytes to JVM


Example2 of using -XX:MaxPermSize VM (JVM) option in java >
java -XX:MaxPermSize=1g MyJavaProgram
It will set maximum value of Permanent Space as 1 gigabyte to JVM


For more explanation and example - Read : What are -XX:PermSize and -XX:MaxPermSize with Differences



What is the maximum perm gen size value you can set on your system, if you aren’t sure about the system configurations?
Try out for -XX:MaxPermSize=256m, if it works then try -XX:MaxPermSize=512m, if it works then try -XX:MaxPermSize=1024m and so on. Be cautious before going beyond 8g.



6) You must also know how to change the heap size JVM parameters >



7) How to set or change permgen size in eclipse?


Open eclipse.ini file, it is located in root eclipse directory. there you can change -Xms and -Xmx parameter to change permgen size.


There you can change -XX:PermSize and -XX:MaxPermSize.


Read : What is eclipse.ini file? How to pass vmargs to java program in eclipse? Changing the eclipse setting, What are best eclipse setting?


SUMMARY>
So in this core java tutorial we learned How to set or change permgen size in tomcat server and eclipse.

Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>




Different type of garbage collectors in java>

>Serial collector / Serial GC (Garbage collector) in java

>Throughput GC (Garbage collector) or Parallel collector in java

>Concurrent Mark Sweep (CMS) collector / concurrent low pause garbage collector in java


eEdit
Must read for you :