lundi 2 mars 2015

Wait for any task to finish, then start a new one



I'm wondering how could I, without doing my own implementation of reporting using blocking queues and similar, as easily as possible implement the following scenario:


I have K * N tasks, every batch of N tasks is a bit different.



  1. Submit the first batch of N tasks (the work is done concurrently on every task)

  2. When any of the tasks finishes submit a new one (taking it from the second batch)


The second point is repeated until all of the tasks are finished.


Should I use a CyclicBarrier and submit a task when there's one thread waiting? I guess I'd have to use a blocking queue to guarantee that I won't submit the same task twice.




Aucun commentaire:

Enregistrer un commentaire