I am facing a problem in understanding following quote of VaadinSession.getCurrent()
Gets the currently used session. The current session is automatically defined when processing requests to the server and in threads started at a point when the current session is defined (see InheritableThreadLocal). In other cases, (e.g. from background threads started in some other way), the current session is not automatically defined.
Specifically following point is difficult to understand for me,
... in threads started at a point when the current session is defined (see InheritableThreadLocal).
What does that mean ?
My understanding is if thread is created before the new Session has been defined or in the old session then it will not refer to the current newly created Session.
Currently I have Thread Pool
and some threads are referring to the old session which is now closed then I will face the problem in using session in those threads.
I'm using spring
with vaadin
, specifically @Async
method calls.
@Async
public static methodX() {
//I have used session inside it
}
Problem is say, thread1
has been used to execute methodX
, now I have used session session1
and after the user logout this session1
will be closed.
Now, when new user logs in to the system which has session2
and executes this method with thread1
again then this method has still used session1
instead of session2
and that creates problem when methods tries to fetch data from the closed session1
.
My Questions :
- Why
Vaadin
can not provide or notify old threads (i.e. threads which belongs to the old(closed) session) about the newly definedSession
? - What is the best way to provide the session to these threads ?