How Can We Prevent Busy Waiting in Java ?

There is a simple way to prevent busy-waiting in Java. We can just put the current thread to sleep for given amount of time.

It can be done by calling sleep() method of java.lang.Thread class. We can pass the number of milliseconds to sleep() method as an argument.



You May Interest

Enumeration and Iterator, Which One Has Better Performance in Jav ...

Does Java Allow Virtual Functions ?

What is the Difference Between Throw and Throws in Java ?

What is the Different Type of Tag Library Groups in JSTL ?

What is the Difference Between pass by reference and pass by valu ...