3
我在View模式中爲我的jsf/icesfaces應用程序使用了開放會話。 像往常一樣,servlet過濾器打開和關閉「web服務器線程」開始和結束處的所有休眠會話。休眠'在視圖中打開會話'和異步任務
我現在的問題是,我用例如異步任務。從數據庫加載大對象列表。因此,我正在創建一個「手動」的執行任務的新線程。
現在我的問題:處理這種異步任務的休眠會話的最佳方式是什麼?我應該在線程本身手動創建一個會話,還是像線程一樣有servlet過濾器(當線程啓動時會打開會話,並在線程結束時關閉會話)?
我會感謝任何最好的practives或類似。謝謝。
下面是它創建線程的代碼:
protected static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5,
15, 50, TimeUnit.SECONDS, new LinkedBlockingQueue(20));
// called by action method of a button
private void asyncLoading() {
SessionRenderer.addCurrentSession(this.renderGroup);
threadPool.execute(new Thread() {
// do the thing to do (...)
}
}