Hibernate 'open session in view' and asynchronous tasks

I am using the Open Session in View template for my jsf / icesfaces application. As usual, the servlet filter opens and closes all hibernation sessions at the beginning and end of the “web server stream”.

Now my problem is that I use asynchronous tasks, for example. loading large lists of objects from the database. Therefore, I create a new thread "manually", which performs the task.

Now my question is: what is the best way to handle hibernation sessions for such async tasks? Do I have to manually create a session in the thread itself or is there something like a servlet filter also for threads (something that opens the session when the thread starts and closes it when it ends)?

I will be grateful for the best practitioners, etc. Thank.

Here is the code that creates the stream:

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 (...)
                }
}
+3
source share
1 answer

, "Open Session in view" : , ThreadLocal, . , , ThreadLocal. , " " factory, , ( ), "// , (...)".

0

Source: https://habr.com/ru/post/1770065/


All Articles