My current implementation counts how many tasks are added to the pool and decrements when the complete their task.
I then tell the main code to repeat + sleep until the active tasks drop below the thread pool size before I add another task.
I feel there must be a better way?
I do not want the tasks placed in a queue, but I would happily wait for the pool to tell me it’s ready to receive more tasks.
For background, I have a web-service that I wish to invoke and it involves around 150,000 HTTP calls, I plan to do 50 at a time until the full 150,000 calls have been completed, this is why I can’t queue all tasks as I will exhaust my RAM.
I do not want any blocking to be on a timeout - I’m happy to wait as long as necessary for the thread pool to have space for new tasks.
Any suggestions on how this can be achieved?