Java – a separate execution queue for a single executor to track the remaining data
In my jetty service, I have an endpoint that triggers a large number of threads I am currently using threadexecutiorpool to execute my runnables But I want to know how many jobs remain for each single request to the endpoint and allow multiple concurrent requests
My idea is to make a separate queue for each request and have some executors, which just pull out of each queue in a circular way I want to know if such a thing exists and can be used out of the box
Please note that I don't care about the execution order What I care about is that each request (i.e. session) is given the same time, and for each session, I can find the number of threads that have not been started / completed
So I guess a multiqueue executor or something like that?
Solution
I will properly use your futures with the executioncompletionservice If you use ECs, your network request will be notified immediately after each task is completed so that they always know the number of tasks remaining
Then "equal time" is not guaranteed, and there is a race condition when submitting a job to the thread pool because it has FIFO nature The effectiveness of this solution depends on how you handle the relevant information