What is the difference between a wait()
and sleep()
in Threads?
Is my understanding that a wait()
-ing Thread is still in runni
wait()
is a method of Object
class.
sleep()
is a method of Thread
class.
sleep()
allows the thread to go to sleep
state for x milliseconds.
When a thread goes into sleep state it doesn’t release the lock
.
wait()
allows thread to release the lock and goes to suspended state
.
This thread will be active when a notify()
or notifAll()
method is
called for the same object.