Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequestContextHolder.getRequestAttributes() getting null after @Async

We are using @Async for multithreading. Untill each multithreading method i can see values for RequestContextHolder.getRequestAttributes().

But when i debug inside the method i'm getting request attributes as NULL.

Any thoughts?

like image 420
universe Avatar asked Oct 25 '25 05:10

universe


1 Answers

To get around this issue we created a ContextAwareRunnable Object that was pre-populated with the current requestHolder, securityContextHolder, etc, so that all spawned threads would be able to execute as if it were running in the main thread.

like image 92
Dan Avatar answered Oct 26 '25 19:10

Dan