Thread.sleep() to me seems like a really useless concept because the only way I see it working is in the following scenarios
public void someFunction()
{
//thread does something
Thread.sleep(50000);
//now other threads do something
}
The problem is that for me this is just asking for trouble. I mean this can either be to long in which case at best you may have a performance issue and it may be too long and other threads may wait for the result in which case the situation may become critical.
I mean there are other way like using synchronized and wait which seem much more efficient.
So my question is, are there any situations where using thread sleep is the best option?
It would be impossible to write java.util.Timer without a sleep() method, or at least it would require you to abuse the wait() method, and write a lot of extra code around it to protect against spurious wakeups.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With