简体   繁体   English

java.lang.OutOfMemoryError:PermGen空间解决方案

[英]java.lang.OutOfMemoryError: PermGen space solution

Similar questions are there but none answers by concern .. 那里有类似的问题,但是没有答案。

Here it says that "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 在这里它说,“一个黑客来解决这个问题,就是JDBC驱动程序的类加载器加载比应用的classloader,您可以通过在Web应用程序的war文件传输驱动程序的jar到Tomcat的lib,而不是捆绑它做到这一点

Did not understand what it means to load by common class loader and how is it different from application classloader. 不了解通过普通类加载器加载的含义以及与应用程序类加载器的区别。

This means that the ClassLoader loading the JDBCDriver class is the class loader of your application server which is a parent of your application classloader. 这意味着,加载JDBCDriver类的ClassLoader是应用程序服务器的类加载器,它是应用程序类加载器的父级。 Therefore, the driver is available for every application on your server and not reloaded on every restart of your application (which can lead to permgen trouble if you are not unregistering it properly) 因此,该驱动程序可用于服务器上的每个应用程序,而不会在应用程序的每次重新启动时重新加载(如果未正确注销它,可能会导致permgen问题)

Every time you deploy an application and load a class from there (to use it), it will be loaded by the application classloader. 每次部署应用程序并从那里加载一个类(以使用它)时,应用程序类加载器都会加载它。 the more applications, the more "same" classes are loaded. 应用程序越多,加载的“相同”类就越多。 If you use tomcats' "common" classloader, the class will only be loaded once per tomcat installation. 如果您使用tomcats的“通用”类加载器,则该类将在每次tomcat安装中仅加载一次。

OutOfMemoryError: PermGen space is usually only a problem if your using the hot redeploy feature of Tomcat. OutOfMemoryError: PermGen space如果您使用Tomcat的热重新部署功能,那么OutOfMemoryError: PermGen space通常只是一个问题。 It can also occur if you simply have a very large number of classes being used in your deployment. 如果您只是在部署中使用了大量的类,那么也会发生这种情况。

Increasing the amount of PermGen available in the VM will solve the large number of classes problem. 增加VM中可用的PermGen数量将解决大量的类问题。 That can be done by adding -XX:MaxPermSize=128m or -XX:MaxPermSize=256m to the environment variable JAVA_OPTS or CATALINA_OPTS (this can usually be done in Tomcat launch script). 这可以通过将-XX:MaxPermSize=128m-XX:MaxPermSize=256m到环境变量JAVA_OPTSCATALINA_OPTS来完成(通常可以在Tomcat启动脚本中完成)。 If you are launching Tomcat directly you can export these environment variables in your shell. 如果直接启动Tomcat,则可以在Shell中导出这些环境变量。

Unfortunately this doesn't completely solve the redeploy issue it only make it so you can redeploy more times before running out of PermGen. 不幸的是,这不能完全解决重新部署问题,而只能解决这个问题,因此您可以在PermGen耗尽之前重新部署更多次。 To fix this issue you'll need to make sure your web app unloads correctly and completely. 要解决此问题,您需要确保您的网络应用正确正确地卸载。 This involves making sure all threads started by your webapp stop, and JDBC drivers loaded are unregistered properly among other things. 这涉及确保由您的webapp启动的所有线程都停止,并且加载的JDBC驱动程序已正确注销。 The other way to solve this is to not use hot redeploy and restart Tomcat when making changes to the application. 解决此问题的另一种方法是在更改应用程序时不使用热重新部署并重新启动Tomcat。

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

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