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: Problems with numbers of threads in tomcat server
PostPosted: Wed Apr 05, 2006 3:16 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
I have problems with the number of threads in my tomcat Server. Everytime I open a database connection through the HibernateUtil Class a new thread is started and this thread is never closed anymore. So on every click a new Thread is started and this causes Tomcat to crash after same 1000 requests and I get a outofMemoryError...

I'm opening the Connection through the database with the following code:
Code:
Session session = HibernateUtil.currentSession();
     Transaction tx = null;
      try {
         tx = session.beginTransaction();
                    ....
        tx.commit();


And finally I'm closing it again:

Code:
HibernateUtil.closeSession();


Do I have forgotten something or what is wrong?

My System: RedHat Enterprise, Tomcat 5.5.9, JRE 1.4.2_10


Hibernate version:
3.1.2

My HibernateUtil CLass:
Code:
public class HibernateUtil {

   private static Logger logger = Logger.getLogger(HibernateUtil.class);

   private static final SessionFactory sessionFactory;
   
   
   /**
    * Anlegen einer Sessionfactory. Dabei wird das Hibernate.cfg.xml ausgelesen
    */
   static {
      try {
         // Create the SessionFactory
         sessionFactory = new Configuration().configure()
               .buildSessionFactory();
         
      } catch (Throwable ex) {
         logger.error("Initial SessionFactory creation failed.", ex);
         throw new ExceptionInInitializerError(ex);
      }
   }
   
   
   
   public static final ThreadLocal session = new ThreadLocal();

   /**
    * Öffnet eine neue Hibernate Session, falls noch nicht vorhanden
    *
    * @return Hibernate Session
    * @throws HibernateException
    */
   public static Session currentSession() throws HibernateException {
   
     
      Session s = (Session) session.get();
      // Open a new Session, if this Thread has none yet
      if (s == null) {
         s = sessionFactory.openSession();
         session.set(s);
      }
      return s;
   }
   

   /**
    * Schließen der Hibernate Session
    *
    * @throws HibernateException
    */
   public static void closeSession() throws HibernateException {
      Session s = (Session) session.get();
      session.set(null);
      if (s != null)
         s.close();
     

   }
}


[/code]


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.