I want a Thread-Pool that provides a maximum of X Threads to process tasks, so far no problem. However each submitted Task can specify an IO-Target which is specifically limited (say Y).
So a submitted IOTask returns the target “google.com” with limit 4 (Y) and the pool has a global limit 16 (X). I want to submit 10 google.com-tasks where only 4 are processed in parallel and the pool has 12 threads free for other tasks.
How can I achieve this?
You can wrap two ExecutorService instances in a custom class and manually manage the submission of tasks as follows:
This allows you to use 4 threads to do the IO operations and leaves the other 12 threads to service the other tasks.