Is it possible to preserve the order of threading as they hit await when countDown is reached.
If thread 1 calls await before thread 2, then they should be reschudeled in the same order.
Does that even make any sense :) ?
Is it possible to preserve the order of threading as they hit await when countDown is reached.
If thread 1 calls await before thread 2, then they should be reschudeled in the same order.
Does that even make any sense :) ?
It seems like you're talking about some sort of fairness in a CountDownLatch
.
Fairness is not really a concern for countdown latches in general (and especially in Java and its java.util.concurrent
implementation). When the predefined number of countdowns is reached, the latch will signal all the threads that have been waiting for it.
Starvation or scheduling order are orthogonal to the latch functionality at that point - there's no notion of controlled selection from the set/queue of waiting threads, as you may have with a semaphore or a mutex.
Dimitar Dimitrov said,
...there's no notion of controlled selection from the set/queue of waiting threads, as you may have with a semaphore or a mutex.
And that's because a single operation on a Semaphore or a Mutex can only ever release one waiting thread. If multiple threads are waiting, you can define the order in which they are released by saying that the first operation releases this one, and the next operation releases that one, and so on.
CountDownLatch is different because, what sense does it make to try to define an order when the ideal behavior is for a single operation to release all of the waiting threads at the same instant?