Monday, November 30, 2009

java.lang.OutOfMemoryError: PermGen space on java Tomcat server, linux


I got this error last day when try to open an jsp page,

server is Tomcat5.5 and os is linux

I found this link http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ it was very helpful to fix the issue

1. I just added the following code to my catalina.sh file

JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m"


2.
You can create jsp page with the following code to evalute your memory details


# <%@ page import="java.lang.management.*, java.util.*" %><%

# response.setContentType("text/html");

# Iterator iter = ManagementFactory.getMemoryPoolMXBeans().iterator();

# while(iter.hasNext()){

# MemoryPoolMXBean item = (MemoryPoolMXBean) iter.next();

# MemoryUsage mu = item.getUsage();

# long used = mu.getUsed();

# long committed = mu.getCommitted();

# long max = mu.getMax();

# %>

# MEMORY TYPE: <%=item.getName()%>

# Used: <%=used%>

# Committed: <%= committed%>

# Max: <%=max%>

# <%}%>



The output look like

localhost
MEMORY TYPE: Code Cache
Used: 4 mb
Committed: 4 mb
Max: 48 mb
------------------------------------
MEMORY TYPE: PS Eden Space
Used: 25 mb
Committed: 33 mb
Max: 54 mb
------------------------------------
MEMORY TYPE: PS Survivor Space
Used: 0 mb
Committed: 1 mb
Max: 1 mb
------------------------------------
MEMORY TYPE: PS Old Gen
Used: 10 mb
Committed: 227 mb
Max: 455 mb
------------------------------------
MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 64 mb
------------------------------------


After add this code JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m"
I got PS Perm Gen size as

MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 256 mb

No comments:

Post a Comment