我有JSF Web應用程序。我使用的是JSF 2.1.9,Hibernate 4.1.4,GlassFish 3.1.2,PrimeFaces 3.4.1。問題是,使用的堆大小緩慢增加,並在2-3天后達到最大堆大小。然後我必須重新啓動GlassFish。使用的堆大小不斷增加
堆轉儲:
在開始的時候,我點擊應用中的所有網頁和使用的堆大小爲100 MB:
一壓腳提升1-2天,使用的堆大小提高到300 MB(在此期間,使用相同的網頁):
我把小號堆中最常用的類的截圖。
在char[]
類的實例,也有太多的SQL查詢字符串這樣的:
也許沒有隻有一個問題,但我可能會開始從這一解決。在我的網頁中,我通常從數據庫中選擇一些對象並進行渲染。這裏有一些豆類: 圖像(索引控制器):
@Named("indexController")
@SessionScoped
public class IndexController implements Serializable {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("imagePU");
public List<Image> getImages() {
EntityManager em = emf.createEntityManager();
List<Image> result;
try {
EntityTransaction entr = em.getTransaction();
boolean committed = false;
entr.begin();
try {
Query query = em.createQuery("SELECT i FROM Image i ORDER BY i.imageId DESC").setMaxResults(12);
result = query.getResultList();
entr.commit();
committed = true;
} finally {
if (!committed) {
entr.rollback();
}
}
} finally {
em.close();
}
return result;
}
}
標籤圖片:
@Named("galleryBean")
@SessionScoped
public class GalleryBean implements Serializable {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("imagePU");
public List<TaggedImage> getTaggedImages() {
EntityManager em = emf.createEntityManager();
List<TaggedImage> result;
try {
EntityTransaction entr = em.getTransaction();
boolean committed = false;
entr.begin();
try {
Query query = em.createQuery("SELECT ti FROM TaggedImage ti GROUP BY ti.tag ORDER BY ti.taggedImagesId DESC");
result = query.getResultList();
entr.commit();
committed = true;
} finally {
if (!committed) {
entr.rollback();
}
}
} finally {
em.close();
}
return result;
}
}
順便說一句,我不應該執行干將業務邏輯,但我認爲這不是主要我的問題的原因。我需要幫助和一些建議。如果需要,我可以提供更多信息。
感謝您的幫助。
會話超時是5分鐘。 5分鐘後,這些都必須從堆中釋放出來嗎?我正在測試這個應用程序,只有1個活躍用戶 – Deniz