Difference between calling wait() and sleep() method in Java .
wait()
|
sleep()
|
wait() is object class method.
|
sleep() is a thread class method.
|
wait() should be called from the synchronized method or block.
|
There is no such requirement to call sleep() method.
|
wait() is normally done on condition .And wait till the conditions
become true.
|
sleep() is used just to put thread on sleep for some period of time.
|
wait() applies on the object of the class.
|
sleep() applies on the current thread.
|
Waiting thread only got wake if notify() or notifyAll() method is
called on same object.
|
It wake up thread as time expires.
|
wait() is used for muti-thread synchronization.
|
sleep() is used for time-synchronization.
|
wait() is used for inter-thread communication.
|
sleep() is used to pause current thread execution for some time.
|
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial

No comments:
Post a Comment