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