0

I have a web application which uses Hibernate + OpenJPA for database connection. When this application is undeployed using tomcat manager, and then when we take a memory dump and check the class objects in the dump I see many Hibernate, Log4j and servlet class object in the dump. Even though when I am calling the proper shutdown for each of them. Here is the code which I am using to shutdown them. It is called in contextDestroyed(ServletContextEvent sce)

EntityManager em = EntityManagerHelper.getEntityManager();
/* Get a session.*/
Session session = (Session) em.getDelegate();
System.out.println("Calling session close.");
closeSessionFactory(session.getSessionFactory());

System.out.println("Closing EntityMnanager.");
EntityManagerHelper.closeEntityManagerFactory();

System.out.println("De-registering the JDBC drivers.");
deregisterJDBCDrivers();

System.out.println("Shutting down log4j.");
org.apache.log4j.LogManager.shutdown();

Why I am still seeing the class object in the dump after calling the shutdown/close method calls? How to prevent it?

Natraj
  • 397
  • 4
  • 9
  • 35
  • Possibly because they haven't been garbage collected yet? But you're also using a wickedly old version of Tomcat, you might want to do some tests with more recent versions to see if that changes anything. – Gimby Feb 10 '15 at 10:34
  • Have you tried [this](http://stackoverflow.com/a/88262/7345) solution? – mindas Feb 10 '15 at 11:31

1 Answers1

0

I would advise to dig through a heap dump to see what is retaining references to your classloader. I know OpenJPA has an issue where it fails to cleanup after itself. I haven't heard of this problem on tomcat, but it is certainly possible. For giggles, try to call org.apache.openjpa.enhance.PCRegistry.deregister(ClassLoader) on shutdown.

Check out OPENJPA-2538 for details.

Rick
  • 3,830
  • 1
  • 18
  • 16