java PermGen 空间异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7383658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:44:25  来源:igfitidea点击:

PermGen space exception

javajboss

提问by Navnath

I m using JAVA 5 (32 bit) for my application running on JBoss. But it working fine only for 32bit. As we deploy it on 64bit java5, it throws an Exception

我在 JBoss 上运行的应用程序使用 JAVA 5(32 位)。但它仅适用于 32 位。当我们在 64 位 java5 上部署它时,它抛出一个异常

"java.lang.OutOfMemoryError: PermGen space" exception

Is there any Patch required? Is any code code change required?

是否需要任何补丁?是否需要更改任何代码代码?

Thanks in advance.

提前致谢。

回答by gigadot

I have got the same prolem when I run my web application under tomcat or jetty. Permanent genration memory is used for loading the classes and the idea is that "Classes are loaded once and forever". Since I am using quite a lot of libraries and Spring framework, this memory is filled up very quickly espectially when I redeploy the web application several time with out restarting the servlet container.

当我在 tomcat 或 jetty 下运行我的 Web 应用程序时,我遇到了同样的问题。永久代内存用于加载类,其思想是“类加载一次并永远”。由于我使用了相当多的库和 Spring 框架,因此当我多次重新部署 Web 应用程序而不重新启动 servlet 容器时,这些内存会很快被填满。

I found that increasing the maximum permanent generation is not sufficient. You also need to allow the garbage collection to removed the unused classes at runtime, otherwise it will be filled up and throws PermGen space exception. Here are the JVM options that I added for my servlet containers,

我发现增加最大永久代是不够的。您还需要允许垃圾收集在运行时移除未使用的类,否则会被填满并抛出 PermGen 空间异常。这是我为 servlet 容器添加的 JVM 选项,

-XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled

-XX:MaxPermSizeis used to set the maximum value of permanent generation. This should be greater than the default size.

-XX:MaxPermSize用于设置永久代的最大值。这应该大于默认大小。

-XX:+CMSClassUnloadingEnabledthis option is used to allows JVM to unload the class at runtime. By default, class unloading is disable. For Java 5, please read this.

-XX:+CMSClassUnloadingEnabled此选项用于允许 JVM 在运行时卸载类。默认情况下,类卸载是禁用的。对于 Java 5,请阅读

-XX:+UseConcMarkSweepGC, in order for class uploading option to work, this option must also be set (ref)

-XX:+UseConcMarkSweepGC, 为了使类上传选项起作用,还必须设置此选项(ref

Also, you should consider upgrading your JVM version. Java 5 is too old.

此外,您应该考虑升级您的 JVM 版本。Java 5 太旧了。

回答by 9000

64-bit Java has twice as long pointers as 32-bit has. Since most of your objects are composed of pointers (references to other objects), you need significantly more memory to run. You run a 64-bit version because your app needsmore than 4GB allocated in the first place, don't you? If you don't, you're better off with a 32-bit JVM.

64 位 Java 的指针长度是 32 位的两倍。由于您的大多数对象都由指针(对其他对象的引用)组成,因此您需要更多的内存来运行。您运行 64 位版本是因为您的应用程序首先需要分配超过 4GB 的空间,不是吗?如果不这样做,最好使用 32 位 JVM。

Play with -XX:MaxPermSize=when starting your server.

-XX:MaxPermSize=启动服务器时播放。

回答by Peter Lawrey

Is there any Patch required?

是否需要任何补丁?

Yes, Using the 64-bit Java 6 or 7 which uses 32-bit references by default. Java 5.0 uses 64-bit references. I don't imagine this will be added to Java 5.0 as it hasn't been freely supported for almost two years. (You can pay to support it BTW)

是的,使用默认使用 32 位引用的 64 位 Java 6 或 7。Java 5.0 使用 64 位引用。我不认为这会被添加到 Java 5.0 中,因为它已经近两年没有得到免费支持。(顺便说一句,您可以付费支持它)

In the Sun/Oracle JVM, objects are 8 byte aligned. The JVM uses this fact to use 32-bit references to address 32 GB of memory. (8 * 4G). With direct and memory mapped memory you can use more than 32 GB.

在 Sun/Oracle JVM 中,对象是 8 字节对齐的。JVM 使用这个事实来使用 32 位引用来寻址 32 GB 的内存。(8 * 4G)。通过直接内存和内存映射内存,您可以使用超过 32 GB。

回答by Nirmal

Create one environment variable with following parameter/values :

使用以下参数/值创建一个环境变量:

varible name = JAVA_OPTS

variable value = -Xmx1000M -XX:MaxPermSize=512m