Java – under what circumstances thread Is sleep () the best way to pause a thread?
•
Java
Thread. Sleep () seems like a very useless concept to me, because the only way I see it work is in the following scenario
public void someFunction() { //thread does something Thread.sleep(50000); //Now other threads do something }
The problem is, for me, it's just causing trouble I mean, this can be very long. In this case, you may encounter performance problems and may be too long, while other threads may wait for results. In this case, the situation may become very serious
I mean, there are other ways, such as using synchronized and wait, which seems more efficient
So my question is, is there the best choice to use thread sleep?
Solution
Write Java. Java without the sleep () method util. Timer is impossible, or at least it will require you to abuse the wait () method and write a lot of extra code around it to prevent false wakeups
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码