-->
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.  [ 7 posts ] 
Author Message
 Post subject: Out of memory error
PostPosted: Mon Feb 02, 2004 12:50 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 10:26 am
Posts: 21
Hello,
i am new to hibernate and trying to use it in a simple client server application. i hope i will try to explain well the situation.

1- i have a message class, which contains a client and a session object. , session object contains several session information and an Arraylist of event objects.

2 - Client side is producing an XML string for a message and sending it to server via sockets.

3- Server produces a reader thread for each incoming connection. server takes the XML message in the thread and produces an object from the XML string (using XStream, dont ask why i am converting to XML, is another issue..). Then it produces a persistent version of the message (including persistend versions of session, client id and events in it)

4- then it tries to insert it to the DB (HSQLDB) in the same socket reading thread.

For testing i am sending randomly produced messages sequentally from the client with 150ms intervals. if i send 100 messages, server handles it well but it seems it inserts each message after quite a delay.
When i tried to run two seperate client application, this time, after some time application gives me "Out of memory error".

my insertion code is stg like this (some lines of code is erased for simplification):
Code:

public class Inserter {
    Configuration cfg = new Configuration();
    public Inserter() throws MappingException {
        cfg.addClass(PMessage.class)
                .addClass(PSession.class)
                .addClass(PClient.class)
                .addClass(PEvent.class);
    }
    .....
    public void insertMessage(PMessage m) throws Exception {
        // configure hibernate
        SessionFactory sf = cfg.buildSessionFactory();
        // Open Session
        Session sess = sf.openSession();
        // start tr, save message and other objects within
        Transaction t = sess.beginTransaction();
        sess.save(m.getSession());
        sess.save(m.getClient());
        sess.save(m);
        t.commit();
        sess.close();
    }
}


have i understood the hibernate wrong? or stg wrong with my approach?
i can send some details of mapping files etc if anyone wants.
Thanks for this great software,

Ahmet


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:24 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Your insertMessage() method creates a SessionFactory every time it is invoked - and doesn't destroy it...

You should:
- create the SessionFactory once when your Inserter is initialized (for example - or at application init if you are using Hibernate at other places);
- then create a new session when you need to persist your message...

The SessionFactory is an heavy element that should be created only once and reused later when a session is needed...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:39 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 10:26 am
Posts: 21
Thanks!!!
i am trying it now. i was actually suspicious about that because the threads were not finishing. i wil post the further experiments.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:54 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 10:26 am
Posts: 21
perfect, it worked like a charm! i bombarded server with multiple clients and it saved all the messages very well. thanks a lot....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 5:49 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
ahmetaa wrote:
perfect, it worked like a charm! i bombarded server with multiple clients and it saved all the messages very well. thanks a lot....


Et voila... BTW you should have read the doc and examples...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 7:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
We could add a random RTM in signature :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably we could autogenerate it according to the number of the posting in the thread, like first one - RTM, second one - RTFM, third one - sorry, thought it was in the manual, fourth one - okay, could be an interesting problem :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.