I'm not 100% sure I understand your requirement, but I think you can use a ExecutorCompletionService
.
This class wraps an Executor and you can use submit
to add tasks, and take
or poll
to retrieve the next completed task. If there are no completed tasks yet, take
will block until one task completes.