I have scenario: I want to wait, until something is false. Usually takes likes 20 seconds or so.
while(foo) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Or just go like this?
while(foo) {
}
Busy waiting for 20 seconds is not a good idea – and sleeping for 5 seconds means you might miss the signal by 5 seconds. Can’t you use a different way, such as a CountdownLatch: