You can create queues for each group, and when the task completes, you read the corresponding queue and, if necessary, send the next task.
- , Runnable . JDK , Guava, ExecutorService ListeningExecutorService. , ListenableFuture Java Future. ListenableFuture , . .