I'm trying to run a list of threads from a main, where one of them, let's call it tLast
, should be started individually after the others entered waiting state. I know about t.join
but as I understand it works only if the thread finishes it's work, and as I understand waiting doesn't count.
So far I tried this, after starting all threads but tLast
:
boolean inSleepState = false;
while(!inSleepState){
inSleepState = true;
for(Thread thread: threads){
if(thread.checkState != Thread.state.WAITING){
inSleepState = false;
break;
}
}
}
tLast.start()
The main problem I see with this is that this is a busy wait, which is bad practice and ill adviced as far as I know, But I can't think of another way to do this. Btw I realise I can wait for each thread Individually and spare iteration over threads
, but either way this is a busy wait.
CountDownLatch
. – chrylis -cautiouslyoptimistic-