Read more: http://javarevisited.blogspot.com/2012/01/tomcat-javalangoutofmemoryerror-permgen.html#ixzz3QDWa3Zqi

Tomcat web server often suffers from java.lang.OutOfMemoryError: PermGen space whenever you deploy and undeploy your web application couple of time. No matter you are using tomcat6tomcat7 or using bundled tomcat in Netbeans or Eclipseyou will face this error now and then while developing web application on tomcat server. I thought about this article after writing 2 Solution of OutOfMemoryError in Java. I have touched this issue there but then I thought to write separate tutorial for tomcat outofmemoryerror because I am getting this error too frequently.
 
In this article we will see what causes java.lang.OutOfMemoryError: PermGen Space in tomcat and how to fix java.lang.OutOfMemoryError: PermGen Space in tomcat server.
 

Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution

Cause of OutOfMemoryError in PermGen space in Tomcat:

PermGen Space of heap is used to store classes and Meta data about classes in Java. When a class is loaded by a classloader it got stored in PermGen space, it gets unloaded only when the classloader which loaded this class got garbage collected. If any object retains reference of classloader than its not garbage collected and Perm Gen Space is not freed up. This causes memory leak in PermGen Space and eventually cause java.lang.OutOfMemoryError: PermGen space. Another important point is that when you deploy your web application a new Clasloader gets created and it loads the classes used by web application. So if Classloader doesn't get garbage collected when your web application stops you will have memory leak in tomcat.
 

Solution of Tomcat: OutOfMemroyError:

1) Find the offending classes which are retaining reference of Classloader and preventing it from being garbage collected. Tomcat provides memory leak detection functionality after tomcat 6 onwards which can help you to find when particular library, framework or class is causing memory leak in tomcat. Here are some of the common causes of java.lang.OutOfMemoryError: PermGen space in tomcat server:
 
1) JDBC Drivers:
JDBC drivers are most common cause of java.lang.OutOfMemoryError: PermGen space in tomcat if web app doesn't unregister during stop. One hack to get around this problem is that JDBC driver to be loaded by common class loader than application classloader and you can do this by transferring driver's jar into tomcat lib instead of bundling it on web application's war file.
 
2) Logging framework:
Similar solution can be applied to prevent logging libraries like Log4j causing java.lang.OutOfMemoryError: PermGen space in tomcat.
 
3) Application Threads which have not stopped.
Check your code carefully if you are leaving your thread unattended and running in while loop that can retain classloader's reference and cause java.lang.OutOfMemoryError: PermGen space in tomcat web server. Another common culprit is ThreadLocal, avoid using it until you need it absolutely, if do you make sure to set them null or free any object ThreadLocal variables are holding.
 
Another Simple Solution is to increase PermGen heap size in catalina.bat or catalina.sh of tomcat server; this can give you some breathing space but eventually this will also return in java.lang.OutOfMemoryError: PermGen space after some time.
 

Steps to increase PermGen Heap Space in Tomcat:

 
1) Go to Tomcat installation directory i.e C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.14\bin in Windows and something similar in linux.
 
2) Add JAVA_OPTS in your catalina.bat or Catalina.sh
 
In Windows:
 
set JAVA_OPTS="-Xms1024m -Xmx10246m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m"
 
In linux:
 
export JAVA_OPTS="-Xms1024m -Xmx10246m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m"
 
You can change the actual heap size and PermGen Space as per your requirement.
 
3) Restart Tomcat.
 
As I said earlier increasing PermGen space can prevent java.lang.OutOfMemoryError: PermGen in tomcat only for some time and it will eventually occur based on how many times you redeploy your web application, its best to find the offending class which is causing memory leak in tomcat and fix it.

Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution的更多相关文章

  1. myeclipse tomcat java.lang.OutOfMemoryError: PermGen space错误的解决方法

    错误代码: java.lang.OutOfMemoryError: PermGen space 原因分析: myeclipse或tomcat的内容分配的不够用,启动失败 解决方法: 1.找到tomca ...

  2. Eclipse中启动tomcat: java.lang.OutOfMemoryError: PermGen space的解决方法

    tomcat启动的时候出现这种错误一般是项目引用了太多的jar包,或者反射生成了太多的类,或者有太多的常量池,导致非堆内存中永久保存区域不够,就有可能会报java.lang.OutOfMemoryEr ...

  3. Tomcat – Java.Lang.OutOfMemoryError: PermGen Space

    很多时候,在开发阶段Tomcat重复的重启过程中会遇到java.lang.OutOfMemoryError : PermGen space 错误. 1 2 3 4 java.lang.OutOfMem ...

  4. Tomcat java.lang.OutOfMemoryError: PermGen space error

    Often time, Tomcat may hits the following java.lang.OutOfMemoryError: PermGen space error. java.lang ...

  5. Eclipse中启动tomcat报错java.lang.OutOfMemoryError: PermGen space的解决方法

    有的项目引用了太多的jar包,或者反射生成了太多的类,异或有太多的常量池,就有可能会报java.lang.OutOfMemoryError: PermGen space的错误, 我们知道可以通过jvm ...

  6. [转]Tomcat启动java.lang.OutOfMemoryError: PermGen space错误解决

    原文地址:http://outofmemory.cn/java/OutOfMemoryError/outofmemoryerror-permgen-space-in-tomcat-with-eclip ...

  7. Tomcat内存溢出(java.lang.OutOfMemoryError: PermGen space)

    Tomcat启动时报如下错误:     java.lang.OutOfMemoryError: PermGen space 解决办法:     配置相关内存大小.其中按照启动tomcat的不同方式,分 ...

  8. Tomcat Xms Xmx PermSize MaxPermSize 区别 及 java.lang.OutOfMemoryError: PermGen space 解决

    解决方案 在 catalina.bat 里的 蓝色代码前加入: 红色代码 rem ----- Execute The Requested Command ----------------------- ...

  9. Tomcat内存溢出(java.lang.OutOfMemoryError: PermGen space)的解决办法

    Tomcat启动时报如下错误: java.lang.OutOfMemoryError: PermGen space 解决办法: 配置相关内存大小.其中按照启动tomcat的不同方式,分如下三种情况 a ...

随机推荐

  1. 使用T-SQL导入多个文件数据到SQL Server中

    在我们的工作中,经常需要连续输入多个文件的数据到SQL Server的表中,有时需要从相同或者不同的目录中,同时将文件中的数据倒入.在这篇文章中,我们将讨论如何同时把一个目录中的文件的数据倒入到SQL ...

  2. Kubernetes 部署kafka ACL(单机版)

    一.概述 在Kafka0.9版本之前,Kafka集群时没有安全机制的.Kafka Client应用可以通过连接Zookeeper地址,例如zk1:2181:zk2:2181,zk3:2181等.来获取 ...

  3. Spring MVC之JSON数据交互和RESTful的支持

    1.JSON概述 1.1 什么是JSON JSON(JavaScript Object Notation,JS对象标记)是一种轻量级的数据交换格式.它是基于JavaScript的一个子集,使用了C.C ...

  4. spark java API 实现二次排序

    package com.spark.sort; import java.io.Serializable; import scala.math.Ordered; public class SecondS ...

  5. 20169211《Linux内核原理及分析》第十二周作业

    Collabtive 系统 SQL 注入实验 实验介绍 SQL注入漏洞的代码注入技术,利用web应用程序和数据库服务器之间的接口.通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串, ...

  6. CSU - 2055 Wells‘s Lottery

    Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...

  7. win10怎么修改svn的用户和密码

    win10怎么修改svn的用户和密码(一般为默认),其他的系统也差不多 方法/步骤 1.方法一: 1.双击我的电脑在c盘找到auth文件夹 C:\Users\系统帐户名\AppData\Roaming ...

  8. 安装部署VMware vSphere 5.5文档 (6-4) 安装配置DB数据库

    部署VMware vSphere 5.5 实施文档 ########################################################################## ...

  9. LOJ P3959 宝藏 状压dp noip

    https://www.luogu.org/problemnew/show/P3959 考场上我怎么想不出来这么写的,状压白学了. 直接按层次存因为如果某个点在前面存过了则肯定结果更优所以不用在意各点 ...

  10. Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组

    题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...