I have a webservice that does multiple small calculations before returning the result. I want to use the ExecutorService provided by Executors.newFixedThreadPool() as a way to implement the Master - Worker pattern (ie. call invokeAll and let the thread wait for all results to finish). Ideally all webservice threads use the same executor service so that they don't all have to create their own thread pool and they can just share one big pool that uses up all of the system's processing time.
Questions I have with this approach:
- is it safe to access the invokeAll function from multiple threads.
- will the executor service just handle the requests sequentially (ie. first all the tasks from thread 1, then those for thread
- is there a way to have say 10 worker threads and have the maximum of threads available depend on the number of requests comming in, so say we have 1 request, it uses all 10 threads for that request. If you have 2 requests, it splits them 5 threads per request etc.