繼續解決this problem,我已經找到了幾個 'org.hibernate.impl.SessionFactoryImpl' 內存泄漏使用MAT:如何釋放多個org.hibernate.impl.SessionFactoryImpl
54 instances of "org.hibernate.impl.SessionFactoryImpl", loaded by "org.apache.catalina.loader.WebappClassLoader @ 0xbb00fb0" occupy 33 962 536 (64,40%) bytes.
Biggest instances:
org.hibernate.impl.SessionFactoryImpl @ 0x3f026c0 - 652 664 (1,24%) bytes.
org.hibernate.impl.SessionFactoryImpl @ 0x49018f8 - 652 664 (1,24%) bytes.
org.hibernate.impl.SessionFactoryImpl @ 0x7b0e2b8 - 652 664 (1,24%) bytes.
org.hibernate.impl.SessionFactoryImpl @ 0x7d65e60 - 652 664 (1,24%) bytes.
...
詳細信息:
DaoSF.java
public final class DaoSF implements Serializable
{
private static final long serialVersionUID = 1L;
private static SessionFactory sessionFactory;
private static Session hibSession;
private synchronized static void initSessionFactory() {
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
sessionFactory = config.buildSessionFactory();
hibSession = sessionFactory.getCurrentSession();
}
public static SessionFactory getSessionFactory() {
initSessionFactory();
return sessionFactory;
}
public static Session getSession(){
return hibSession;
}
}
0 DaoCrud.java的
部分:Bean.java
public void save() {
try {
mydao.save(item);
}
catch (Exception e) {...}
}
}
我在做什麼錯
public void save(Object dataItem) throws Exception
{
session = DaoSF.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
session.save(dataItem);
session.flush();
tx.commit();
if (session != null) session.close();
}
一部分?如何正確使用會話工廠?你可以幫幫我嗎?
謝謝米米,你的建議讓我走向正確的道路,我減少了DaoSF,重新編寫了DaoCrud,問題解決了。所以我接受你的答案。謝謝:) – gaffcz
很高興我能幫到:) – 2011-07-19 15:23:41