what is the difference between sleep() and Wait()?
Answer Posted / amitasite
Thread.sleep() is static method which make current running
thread "not runnable" for specific time. Sleeping thread
doesn't release lock. It will transit to "ready to run"
state after specified time elapsed or other thread interrupts.
wait() can be call on shared object. Wait can be call only
if thread has lock. On calling thread it releases lock on
object and transit to "not runnable" state. It wake ups and
transit to "ready to run" state after other thread that got
lock call notify() or notifyAll() on shared object or call
interrupt().
| Is This Answer Correct ? | 11 Yes | 1 No |
Post New Answer View All Answers
How can you set an applet’s height and width as a percentage?
What is structure of java heap? What is perm gen space in heap?
How to create com object in Java?
How do you sort in descending order in java using collections sort?
What is import java util arraylist?
Explain importance of inheritance in java?
What are the two main uses of volatile in Java?
What is a class component?
What is the functionability stubs and skeletons?
What is java object name?
What is difference between string and stringbuffer?
What is tostring () method?
What is jvm? How its run?
Can java program run without jre?
What is final?