-->
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: Why do I have to close the SessionFactory?
PostPosted: Wed Nov 16, 2011 8:08 am 
Newbie

Joined: Wed Mar 23, 2011 4:24 am
Posts: 2
I am running a quartz job that exports log to a database, but it keeps on running out of memory after some time. I found out after a while that this was caused by SessionFactory not releasing its resources. So by explicitly closing the sessionfactory after each use, the problem goes away. That is ok, but I do not understand why I have to do this. ExportJob creates the sessionfactory, so when ExportJob is out of scope (I suspect Quartz is nulling the reference), its "children" should be freed by GC as well. Why is this not happening?

The following code will run out of memory
Code:
public class ExportJob implements StatefulJob {
    private SessionFactory sessionFactory;

    public ExportJob() { //needed for Quartz
        this.sessionFactory = new Configuration().configure().buildSessionFactory();
    }

    public void execute(JobExecutionContext context) throws JobExecutionException {
      //if I do sessionFactory.close() the problem goes away
    }
}


Hibernate is setup to run against an Oracle 10.2 DB
Quartz 1.8.7
Hibernate 3.5.1-Final


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.