I am developing an simple REST resource with Spring MVC. The resource aggregates some data from other data sources. The processing of request would be much faster when I parallelize all subrequests to other data sources.
I use an TaskExecutor that maintains a pool of threads and these threads are used by main thread that processes an incomming HTTP request. The main thread starts all subtasks, waits until all of them are finished and construct an response.
When the threads processing subtask they need to be in the same Application context as the main thread, becouse they need to read some request scoped beans.
Could you please give me some hint how can I inject the application context to subthreads or is this idea completely wrong by design?