Lets say I have a few groups of threads in java which I want to implement in this way: at each point of time, only one group of threads can run, and the others should wait for their turn (cyclic).
How you would recommend to do so?
Lets say I have a few groups of threads in java which I want to implement in this way: at each point of time, only one group of threads can run, and the others should wait for their turn (cyclic).
How you would recommend to do so?
You can use a
CyclicBarrier
to prevent one group of threads from running while the other group is still progressing. You can release the next group using aCountDownLatch
.What you would do is wait for the group before the current to reset the cyclic barrier before continuing. The barrier would be reset after all the threads countDown the latch.
For example: