I'm utilizing the Open Session in View pattern for my jsf/icesfaces application. As usual a servlet filter is opening and closing all the hibernate sessions at the beginning and the end of a "web server thread".
My problem now is that I'm using asynchronous tasks for eg. loading big lists of objects from the database. Therefore I'm creating a new thread "by hand" which executes the task.
Now my question: what's the best way to handle hibernate sessions for such async tasks? Should I manually create a session in the thread itself or is there something like a servlet filter also for threads (something which opens the session when the thread starts and closes it when it ends)?
I would be grateful for any best practives or the like. Thank you.
Here's the code which creates the thread:
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 (...)
}
}