The server application I am running gets multiple requests for tasks which I want to handle using a task system.
Each task is represented as a Runnable that will demand n number of threads from a thread pool where n is smaller or equal to the thread pool size. The thread pool of course is necessary in order to not overload the CPU with too many threads.
However, some of those tasks can be multi threaded and some can not. That is why it might be necessary for one task to wait for all its specific threads to finish in order to merge the results from those threads for the final result.
If one uses multiple Thread instances one might join those like this:
try { // Wait for all threads to finish their tasks for (Thread thread : threads) { thread.join(); } } catch (InterruptedException e) { e.printStackTrace(); } // Finish job here .. but I'd need something like this using java.util.concurrent.Executor or anything similar that works with a thread pool.