本文介绍了Tomcat内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下简单的网络应用程序:

I have simple web app using :

1-Spring mvc4.1.1

1-Spring mvc4.1.1

2-休眠4.3.10

2-hibernate 4.3.10

3-servlet 3.1

3-servlet 3.1

4-Oracle 12c

4-Oracle 12c

5-Ojdbc6(它存在于tomcat/lib中,而不存在于app/lib中)

5-Ojdbc6 (it existed in tomcat/lib NOT in app/lib)

6-JPA 2.1

6-JPA 2.1

我的持久性xml是:

<?xml version="1.0" encoding="UTF-8"?>
<persistence-unit name="NewpersistenceUnit">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <mapping-file>com/springapp/mvc/DBManagement/EntityMapping.xml</mapping-file>
    <class>com.springapp.mvc.DBManagement.StateEntity</class>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@//localhost:1521/orcl"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
        <property name="hibernate.connection.username" value="system"/>
        <property name="hibernate.connection.password" value="1234546"/>
        <property name="hibernate.archive.autodetection" value="class"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hbm2ddl.auto" value="update"/>
        <property name="hibernate.connection.oracle.jdbc.V8Compatible" value="true"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    </properties>
</persistence-unit>

插入方法是

    public void AddLocation()
{
    EntityManagerFactory emf= Persistence.createEntityManagerFactory("NewpersistenceUnit");
    EntityManager em= emf.createEntityManager();
    EntityTransaction et= em.getTransaction();

    LocationEntity location = new LocationEntity();

    location.setCityname("Newyork");

    et.begin();
    em.persist(location);
    et.commit();
    em.close();

}

当我在tomcat8.0.26中部署和取消部署并导致内存泄漏时请帮助我

when i deploy and undeployed in tomcat8.0.26 and make memory leakplease help me

推荐答案

根据我的经验,在大多数情况下,这是由于现有对tomcats WebappClassLoader的强烈引用引起的.使用的库之一或您的应用程序对WebappClassLoader有很强的引用,可防止WebappClassLoader被垃圾回收.可以按照以下步骤跟踪此类内存泄漏:

In my experience this is in most cases caused by existing strong references to tomcats WebappClassLoader. One of the used libraries or your application has a strong reference to the WebappClassLoader that prevents the WebappClassLoader from being garbage collected.Tracking down such a memory leak could be done following these steps:

  • 使用您的应用程序启动tomcat
  • 重新部署您的应用一次
  • 手动运行垃圾回收并创建一个堆转储(可以通过visualvm完成)
  • 使用Eclipse Memory Analyzer或JProfiler之类的配置文件分析堆转储
  • 找到类型为WebappClassLoader的实例,该实例的属性为started = false
  • 跟踪这些WebappClassLoader实例的GC根(不包括弱引用,软引用和幻像引用)
  • 现在,您应该查看是什么原因导致WebappClassLoader保持活动状态并被阻止进入GC

这是更详细的说明:如何分析泄漏的Web应用程序

这篇关于Tomcat内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:35