This is another popular core interview question. Look at the following table.
yield() vs sleep()
- Both methods are used to stop execution of current thread.
- But the different is, yield() method release its lock of object while sleep() method doesn't release its lock of object.
wait() vs sleep()
- sleep() method allows to thread to go to sleep state for given time. As you know, it doesn't release the lock of object.
- wait() allows thread to release the lock and goes to blocked state. It can be active only by calling notify() or notifyAll() methods.
notify() vs notifyAll()
- notify() method activate the first thread which called wait().
- notifyAll() method activate all threads which called wait(), highest priority thread will run first.
yield() vs join() vs sleep()
Reviewed by Ravi Yasas
on
12:32 AM
Rating:
![yield() vs join() vs sleep()](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb33hnN4wQRg6qPBs7QtCHTyVUzVVd2fudn5ruzSt73wAy5GYPi8PcoW-rCyjimqraAxNYGxdttyZ1mUpy9CEYTT_7GYmUYEzueIsEWm7DzPnqJErx-5-PLiaN8C1GLz6wgaVCrHo8alHt/s72-c/123.jpg)
No comments: