简体   繁体   English

java.lang.OutOfMemoryError:PermGen空间

[英]java.lang.OutOfMemoryError: PermGen space

To all down/close voters : I know this is a exact duplicate of many questions but I tried many answers and still facing issues so added a new question. 对于所有关闭/关闭选民:我知道这是许多问题的完全重复,但我尝试了许多答案,仍然面临问题,因此增加了一个新问题。

Question: I am using eclipse-helios and Tomcat 6 for my spring application and get 问题:我正在使用eclipse-helios和Tomcat 6进行春季应用程序并获得

java.lang.OutOfMemoryError: PermGen space  

WHENEVER I DEBUG MY APPLICATION 无论我如何调试我的申请

I tried 我试过了
1) Adding 1)添加

-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024m
-XX:MaxPermSize=1204m
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled    

to eclipse.ini eclipse.ini
2) Creating setenv.sh and setenv.bat in tomcat_home/bin with following content 2)创建setenv.shsetenv.battomcat_home/bin有以下内容

set JAVA_OPTS="-Xms256m -Xmx512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"   

3) Manually running garbage collector in eclipse. 3)在eclipse中手动运行垃圾收集器。 I enabled this option by 我启用了这个选项

Window -> Preferences -> General -> and select always run in background and show heap status 

4) Restarting Tomcat hundred times. 4)重启Tomcat一百次。
5) Restarting eclipse and sometimes restarting my machine when frustration goes beyond the limit.. 5)当挫折超出限制时,重新启动eclipse并有时重新启动我的机器。
Best part is I still get the error. 最好的部分是我仍然得到错误。
Is there any solution which I should try ? 我有什么办法可以尝试吗?

EDIT : I tried running other application and still get same error also IMHO my application is too small to cause error and my app is running fine on my colleagues setup. 编辑:我尝试运行其他应用程序,仍然得到相同的错误恕我直言我的应用程序太小,不会导致错误,我的应用程序运行良好的同事设置。

Your first 3 options target 2 different JVMs. 您的前3个选项针对2个不同的JVM。 Options #1 and #3 modify eclipse JVM instance, this is the JVM managing your IDE. 选项#1和#3修改eclipse JVM实例,这是管理IDE的JVM。 Option #2 modifies the Tomcat JVM instance. 选项#2修改Tomcat JVM实例。 That's why you see two java.exe files in your task manager (in case of windows) when starting eclipse and Tomcat (assuming those are the only Java apps running). 这就是为什么你在启动eclipse和Tomcat时假设你的任务管理器中有两个java.exe文件(如果是windows)(假设那些是唯一运行的Java应用程序)。

It's important to understand that the Tomcat plugins provided by eclipse WTP (in my case Indigo) do not call the external (OS dependent) scripts to start/stop Tomcat. 重要的是要理解eclipse WTP(在我的案例中是Indigo)提供的Tomcat插件不会调用外部(OS相关)脚本来启动/停止Tomcat。 Instead they spawn the Tomcat JVM directly via the command line ( java.exe ... ). 相反,他们直接通过命令行( java.exe ... )生成Tomcat JVM。 If you want to modify JVM parameters for Tomcat instances you start from within eclipse it is necessary to modify the corresponding Run Configuration . 如果要修改Tomcat实例的JVM参数,请从eclipse中开始修改相应的Run Configuration Try modifying the JVM parameters there, it should work (see screenshot). 尝试修改那里的JVM参数,它应该工作(见截图)。 在此输入图像描述

Try set JAVA_OPTS=-XX:NewSize=128m -XX:MaxNewSize=256m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -Xms512m -Xmx1536m 尝试set JAVA_OPTS=-XX:NewSize=128m -XX:MaxNewSize=256m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -Xms512m -Xmx1536m

The permanent generation is special because it holds meta-data describing user classes (classes that are not part of the Java language). 永久生成是特殊的,因为它包含描述用户类的元数据(不属于Java语言的类)。 Examples of such meta-data are objects describing classes and methods and they are stored in the Permanent Generation. 这种元数据的示例是描述类和方法的对象,并且它们存储在永久生成中。 Applications with large code-base can quickly fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen no matter how high your -Xmx and how much memory you have on the machine. 具有大型代码库的应用程序可以快速填满堆的这一部分,这将导致java.lang.OutOfMemoryError:PermGen,无论你的-Xmx有多高以及你在机器上有多少内存。

对我-Xmx1024m -XX:MaxPermSize=256m就可以了。

What tools have you used to profile your running application? 您使用了哪些工具来分析正在运行的应用程序? I recommend using eclipse mat, although jconsole and visualvm are available with the jdk. 我建议使用eclipse mat,尽管jconk和visualvm可用于jdk。 Do you load a lot of classes in your application, somewhere in a loop? 你是否在一个循环中的某个地方加载了很多类? How about strings? 字符串怎么样? what is the size of the string pool? 字符串池的大小是多少? I am sorry but restarting tomcat, eclipse or the machine is not going to solve the problem; 对不起,重启tomcat,eclipse或者机器不会解决问题; you will need to profile and analyse your application to solve the issue. 您需要分析和分析您的应用程序以解决问题。 Take a heap dump (you can use jmap) and analyse. 进行堆转储(您可以使用jmap)并进行分析。

I would add -XX:PermSize=1024m in the JAVA_OPTS variable, as the error might come from Tomcat. 我会在JAVA_OPTS变量中添加-XX:PermSize = 1024m,因为错误可能来自Tomcat。 I'm not familiar with the eclipse.ini file. 我不熟悉eclipse.ini文件。

I don't know the details about eclipse.ini but I though this was just to set flags when starting Eclipse itself. 我不知道有关eclipse.ini的详细信息,但我只是在启动Eclipse本身时设置标志。 Without impact on running/debugging applications. 不影响运行/调试应用程序。 Personally, whenever I want to alter the settings when running/debugging an application, I simply add the JVM flags in the corresponding run/debug configuration. 就个人而言,每当我想在运行/调试应用程序时更改设置时,我只需在相应的运行/调试配置中添加JVM标志。

Moreover, if you use more than 1 giga perm space, I guess there's something wrong in the code. 此外,如果你使用超过1千兆的烫发空间,我想代码中有问题。 Try to locate the source of the perm space consumption and fix it. 尝试找到烫发空间消耗的来源并修复它。 I don't say it'll be easy, but it'll be needed in order for the application to work properly. 我不是说这很容易,但是为了使应用程序正常工作,它将是必需的。 ...except if 1 giga perm space is really intended, but i've some doubts about it. ......除非1 giga perm空间确实是有意的,但我对它有些怀疑。

What you can look for is for example string.intern() . 你可以寻找的是例如string.intern() If you do this on each request/entry/whatever for arbitrary strings, you'll uselessly fill your perm space since it'll permanently keep a copy of the string. 如果你对每个请求/条目/任意字符串执行此操作,您将无用地填充您的perm空间,因为它将永久保留字符串的副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM