Saral Saxena wrote:
Please advise me on the technical differences between wait() and sleep() methods, the technical justification that I was looking for..!!
Henry Wong wrote:
Saral Saxena wrote:
Please advise me on the technical differences between wait() and sleep() methods, the technical justification that I was looking for..!!
Although these two methods look very similar, they do two different things. One simple and the other somewhat complex.
The sleep() method puts the current thread to sleep(). This is needed when you want a thread to stop doing stuff for a fixed amount of time. Simple.
The wait() method is one-half of the wait/notify mechanism. And if you used other threading systems before, this mechanism provides the functionality of a condition variable. A condition variables purpose is to send notifications/signals between threads. And due to some race condition, it is tied to a lock, which it releases during the operation. This is somewhat complex.
Henry
Saral Saxena wrote:
so you mean to say in sleep() threads sleep for the time period which is mentioned in arguements and it also keeps the lock with itself but in case of wait() the thread can come out before the time period mentioned in arguments and it also releases the locks ..??
the wait() method is part of a condition variable mechanism which is integrated into how to use threading
Saral Saxena wrote:
I have gone with threading tutorial ..Can you please explain in detail wait() method is part of a condition variable mechanism which is integrated into how to use threading..If possible with a small example would be a great help..!! thanks in advance..!!
Khuda Haafiz Muzza 4 Java
Saral Saxena wrote:Hi Folks,
Please advise me on the technical differences between wait() and sleep() methods, the technical justification that I was looking for..!!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |