Tomcat production server sometime will hit the following java.lang.OutOfMemoryException: PermGen space error.
java.lang.OutOfMemoryException: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
java.lang.OutOfMemoryException: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, the solution is actually quite simple.
All you need todo are
1) create setenv.sh or setenv.bat (windows)
Explanation:
All you need todo are
1) create setenv.sh or setenv.bat (windows)
2) add this line if not already exist (depend on what os you are using)
Linux:
export set JAVA_OPTS="-Xms512m -Xmx2g"Linux:
Windows
set JAVA_OPTS="-Xms512m -Xmx2g"
3) Done. Restart Tomcat.
Explanation:
This error are occurs when JVM cannot create new object on memory heap because it pass the heap size. that is why it says out of memory. when your program start it create a heap in memory stated in -Xms parameter. the amount reserved are the number after the parameter. an the suffix after the number are unit size of the heap. k for kilobit; m for megabit; g for gigabit. And also please adjust the amount of memory allocation based on you machine.
-Xmx are the maximum size of the heap in memory. as long as the the object in your memory don't pass this limit you are good. but when you pass this limit then the java.lang.OutOfMemoryException are raised.
Memory Leak:
Normally your program wont pass maximum heap size. But through time your application create more object in the memory and some time collected by java Garbage Collector when the created object not being used anymore by the program. For some reason these object sometimes still have some reference in your program that can cause Memory Leak. If the problem not fixed then Garbage Collector cannot collect this object then eventually the heap became full and you program cannot create more object.
Comments