I\'m using Spring 3. When controller gets requests it passes control to method someMethod()
annotated with @Async
in Service bean and then returns.
The HttpSession
object itself can be used in multiple threads (but is not thread-safe and therefore must be synchronized). However Spring is doing some extra magic e.g. when you have session
-scoped beans. Namely it uses ThreadLocal
underneath to bind current session with thread.
I don't know what is your exact scenario, but apparently Spring tries to retrieve HttpSession
from this ThreadLocal
while you are in another thread - which obviously fails.
The solution is simple - extract session attributes you need in @Async
method and pass them directly. This is by the way much better design - avoid passing HttpSession
object around because it makes testing harder and your code is much less likely to be reused in the future.