what is the difference between sleep() and Wait()?
Answer Posted / suresh
Yes, sleep() and wait() methods are doing same work like prevent Thread Execution some amount of time in different ways.
where wait() is used only in Synchronization area this is called on object.wait(), it is overloaded method.if a thread object calls wait() then that thread will release the lock and wait for notification( notify(), notifyAll()) after getting notification thread will make Runnable.
where as sleep() is used any where it is static method. when sleep() called then thread will enter into sleep state particular amount of time if time expires thread will move into Runnable or Ready state.
In both cases Thread will Interrupted by interrupt().It will checked Exception we have take care of that with try n catch or throws.
| Is This Answer Correct ? | 5 Yes | 1 No |
Post New Answer View All Answers
What is the use of string and stringbuffer?
What is the default value of float and double datatype in java?
What is entry set in java?
What are three types of loops in java?
How do you get the length of a string in java?
What is an anonymous class in java?
How can constructor chaining be done by using the super keyword?
Is an integer an object?
Can we execute a program without main() method?
What is string [] args?
Why are parameters used in functions?
What is a treeset class?
Can a hashset contain duplicates java?
How do you reverse sort a list in java?
What are exception handling keywords in java?