Hi Ranchers,
K&B book page 730 says:
"If you want a guarantee that your threads will take turns regardless of underlying JVM, you can use the sleep() method. This prevents one
thread from hogging the running process while another thread starves." //1
and next it says that "Sleeping is used to delay execution for a period of time, and no object lock is released when thread goes to sleep."
So , my question is, if Thread.sleep() do not release object lock then how can another thread execute ? Or how another thread will start processing and not get blocked?
From sentence 1 I understand that when Thread goes to sleep it will stop executing for a period of time but at the same time it is not giving up processor to some other thread and it will continue running after time expires.
Can someone explain me whats exactly behavior of sleep?
- Vivian