-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate keeping classes loaded in webapp
PostPosted: Wed Jan 02, 2013 1:21 pm 
Newbie

Joined: Thu Mar 27, 2008 1:30 pm
Posts: 6
I'm using Hibernate 4.1.9, Apache Tomcat 7.0.34.

Trying to shutdown my webapp, but Hibernate is leaking references and I'm running out of permgen space. I know I can increase the memory with JVM parameter, but my memory is limited because I have a local developement database running along with couple of other (heavy) application.

Its very annoying to keep restarting Tomcat, after 4-5 deploys. Here is my init and shutdown code:

Code:
   public static void init() {
      if (sessionFactory != null)
         return;

      try {
         Configuration configuration = new Configuration().configure();

         serviceRegistry = new ServiceRegistryBuilder()
               .applySettings(configuration.getProperties())
               .buildServiceRegistry();

         sessionFactory = new MetadataSources(serviceRegistry)
               .buildMetadata()
               .buildSessionFactory();
      } catch (Exception ex) {
         Logger.getLogger(HibernateHelper.class.getName()).log(Level.SEVERE, null, ex);
      }
   }

   public static void shutdown() {
      if (sessionFactory != null && !sessionFactory.isClosed()) {
         sessionFactory.close();
         sessionFactory = null;
      }

      if (serviceRegistry != null) {
         ServiceRegistryBuilder.destroy(serviceRegistry);
         serviceRegistry = null;
      }
   }


These two methods are called from a ContextListener.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.