I am running a Spring MVC
application on Tomcat 8
on Elastic Beanstalk
's worker tier
. For those unfamiliar with Elastic Beanstalk
, whenever an SQS event occurs, Amazon will automatically perform a POST
request to my worker Spring MVC
application. My application then processes the request and returns a 200 (unless something goes wrong obviously).
I would like to use concurrency while processing a single POST
request. For example, let's say I need to perform 10 different expensive calculations. Instead of doing it serially, I'd like to use the ExecutorService
to have 10 threads perform the work concurrently.
- Is this bad practice? If not, are there performance dangers in spinning up new threads in this way?
- How does the allocation of threads actually work (e.g. are they just stolen from Tomcat's thread pool or something else)?
- Should there be a shared thread pool accessible by all Tomcat threads? If so, how big should it be?
- Is it better to just break up the work into more SQS events and essentially distribute the subtasks to Tomcat threads, rather than doing it within a single Tomcat thread?