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.  [ 8 posts ] 
Author Message
 Post subject: Java heap space
PostPosted: Thu Jun 22, 2006 6:29 am 
Newbie

Joined: Tue Jun 13, 2006 11:33 am
Posts: 6
Location: Paris
Bonjour,
j'ai mis en place une application J2EE avec hibernate 3, postgresql 8.1 et tomcat4.1. Mon application se connecte à trois bases de données (BVM, CRM & CS).
Le problème est que les process postgres se multiplient à chaque appel sans se fermer ce qui aboutit à une saturation de la mémoire (java heap space).

J'utilise le plugin hibernate synchronizer pour générer les dao à partir de mes fichiers de mappings et mes java bean. Les dao je les ai adapté de façons à ce qu'ils utilisent HibernateUtil qui gère les sessions :



Code:
public class HibernateUtil {
     
     private static final SessionFactory bvmSessionFactory;
     private static final SessionFactory crmSessionFactory;
     private static final SessionFactory csSessionFactory;
   
      static {
         
         try {
          String pathFile = "WEB-INF/config/bvm.cfg.xml";
          if(!(System.getProperty("bvm.cfg.xml")==null)){
              pathFile = System.getProperty("bvm.cfg.xml");
          }
           File bvmFile = new File(pathFile);
           bvmSessionFactory = new Configuration().configure(bvmFile).buildSessionFactory();
         
         
           pathFile="WEB-INF/config/crm.cfg.xml";
           if(!(System.getProperty("crm.cfg.xml")==null)){
              pathFile=System.getProperty("crm.cfg.xml");
           }     
           File crmFile = new File(pathFile);
           crmSessionFactory = new Configuration().configure(crmFile).buildSessionFactory();
               
         
           pathFile="WEB-INF/config/cs.cfg.xml";
           if(!(System.getProperty("cs.cfg.xml")==null)){
               pathFile=System.getProperty("cs.cfg.xml");
            }
            File csFile = new File(pathFile);
            csSessionFactory = new Configuration().configure(csFile).buildSessionFactory();
           
         } catch (HibernateException ex) {
            throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
         }
      }

      public static final ThreadLocal bvmSession = new ThreadLocal();
      public static final ThreadLocal crmSession = new ThreadLocal();
      public static final ThreadLocal csSession = new ThreadLocal();

      public static Session getBvmSession() throws HibernateException {
         Session s = (Session) bvmSession.get();
         // Open a new Session, if this Thread has none yet
         if (s == null) {
            s = bvmSessionFactory.openSession();
            bvmSession.set(s);
         }
         return s;
      }

      public static void closeBvmSession() throws HibernateException {
         Session s = (Session) bvmSession.get();
         bvmSession.set(null);
         if (s != null){
            s.close();
       
         }
      }
     
      public static Session getCrmSession() throws HibernateException {
            Session s = (Session) crmSession.get();
            // Open a new Session, if this Thread has none yet
            if (s == null) {
               s = crmSessionFactory.openSession();
               crmSession.set(s);
            }
            return s;
         }

         public static void closeCrmSession() throws HibernateException {
            Session s = (Session) crmSession.get();
            crmSession.set(null);
            if (s != null){
               s.close();
               s=null;
            }
         }
         
         
         
         public static Session getCsSession() throws HibernateException {
               Session s = (Session) csSession.get();
               // Open a new Session, if this Thread has none yet
               if (s == null) {
                  s = csSessionFactory.openSession();
                  csSession.set(s);
               }
               return s;
            }

            public static void closeCsSession() throws HibernateException {
               Session s = (Session) csSession.get();
               csSession.set(null);
               if (s != null){
                  s.close();
                  s=null;
               }
            }

   }


Merci pour votre aide, ça fait un moment que je tourne en rond!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 25, 2006 10:02 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Tu utilises un pool de connexion je suppose ? Lequel ?

Tu utilises des datasources de ton serveur d'appli pour te connecter aux BD ? A priori, le fait que des process liés aux connexions soient créés mais pas tués provient ptête du fait que tu ne les fermes pas.

Comment effectues tu tes appels Hibernate ?

@++

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 3:12 am 
Newbie

Joined: Tue Jun 13, 2006 11:33 am
Posts: 6
Location: Paris
heyhey Batmat!
Merci pour ta réponse. Alors, j'utilise C3P0 comme pool de connexion.

Je n'utilise as les datasources de tomcat.
A priori, mes connexions se ferment car l'appel des méthodes closexxxSession dans HibernateUtil se fait bien.

Pour les appels hibernates, j'ai généré des DAO à partir de mes fichiers de mapping grâce au plugin hibernateSynchronizer. A partir de là j'ai créé des méthode pour créer, mettre à jour, supprimer et rechercher mes objets.

Ton fidèle Robino
IG2K pOwEr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:09 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Hey,

J'avais même pas fait attention au nom du posteur :-).

Tu as essayé d'augmenter la taille du tas de ton appli ? (options xms et xmx) Puisque tu accèdes à plusieurs BD, c ptête nécessaire de tuner la JVM que tu lances ?

@++

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:24 am 
Newbie

Joined: Tue Jun 13, 2006 11:33 am
Posts: 6
Location: Paris
Non, mais je ne pense pas que ça soit vraiment nécessaire. Il doit avoir quelque chose que j'ai loupé car les process devraient se terminer après requêtes. Tu as déjà fait un accès multi bases toi?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 11:24 am 
Newbie

Joined: Tue Jun 13, 2006 11:33 am
Posts: 6
Location: Paris
heyhey!
en me replongeant dans la doc, il semblerait qu'il faille passer par les datasources du serveur d'application (e.g. tomcat dans mon cas)
http://www.hibernate.org/hib_docs/v3/re ... ernatejdbc

Quote:
For use inside an application server, you should almost always configure Hibernate to obtain connections from an application server Datasource registered in JNDI.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 4:49 am 
Newbie

Joined: Tue Jun 13, 2006 11:33 am
Posts: 6
Location: Paris
Effectivement, le problème disparait avec les datasources. Tomcat gére les connexions et ça se passe très bien ;-). Cool


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 5:39 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
C'est ptête lié à l'utilisation du pool.

Nous on a ça dans nos datasources déclarées dans le server.xml :

Code:
<Resource
      auth="Container"
      name="jdbc/PofDatasource"
      type="javax.sql.DataSource"
       username="user"
       password="***"
      url="jdbc:oracle:thin:@//machine:port/NOMSCHEMA"
       driverClassName="oracle.jdbc.OracleDriver"

       maxIdle="5"
      maxWait="5000"
      maxActive="10"

      logAbandoned="true"
      removeAbandoned="true"
      removeAbandonedTimeout="5"
     />


Les 3 dernières lignes concernent notamment la gestion des connexions abandonnées (threads associé terminé, mais connexion utilisée par ce thread non fermée).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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

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.